Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Solution] Add endless slides dynamically #864

Open
qroft opened this issue Jun 25, 2023 · 0 comments
Open

[Solution] Add endless slides dynamically #864

qroft opened this issue Jun 25, 2023 · 0 comments

Comments

@qroft
Copy link

qroft commented Jun 25, 2023

I needed cycle2 to add new slides dynamically to the existing cycle-slideshow element.
The problem: if you use the "fadeout" FX the z-index (counting reverse) sooner or later might interfere with your layout or the z-index
setting of any element. Not to mention the amount of DOM data you will end up with (in my case hundreds of GIF animations playing in the background).
If I used "fade" as FX, there always the background visible for like half a second.

So here is my solution:
Pick a random image and add it to the cycle-slideshow
randNumber = Math.rand(0,1000); var newSlide = '<img src="pic"+randNumber+".jpg">'; $('.cycle-slideshow').cycle('add', newSlide);

Use the cycle-afterevent that is always triggered after a new slide has been added
slideshow.on("cycle-after", function (e, opts) { if(opts.slideCount >= 2){ $('.cycle-slideshow').cycle('remove', 0); } });
This way i never have more than 3 slides in my DOM. As soon as the third slide is added, the first one is removed.
Works like a charm.

Would be awesome if some of you could verify for me if this works for you.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant