I’m using THIS plugin to show “n” strings that scroll up every 5 seconds.
In particular you can see the example at the bottom HERE.
This plugin show just one element each time so I did this splitup function that show 7 element:
$.fn.splitUp = function (splitBy, wrapper) {
$all = $(this).find('>*');
var fragment = Math.ceil($all.length / splitBy);
for (i = 0; i < fragment; i++)
$all.slice(splitBy * i, splitBy * (i + 1)).wrapAll(wrapper);
return $(this);
}
$('#list').splitUp(7, '<li><li/>').cycle({
fx: 'scrollUp',
pause: 1,
timeout: 5000,
speed: 2000
});
it works fine.
The problem is: if I have 9 strings it show the first 7 and than only 2 strings…
I’d like to show 7 strings and than 2 + 5. An infinite loop.
How can be possible to do that?
Thanks
Here’s a solution using the
beforeevent and theaddSlide()method available to the options property passed by the event. I added comments to the code to explain what’s going on.CODE (Fiddle Demo: http://jsfiddle.net/QZu2Z/4/)
Extra Note:
One thing to keep in mind although it shouldn’t be a problem for most people is since this does add a new slide every cycle, having your browser open on the page for a long period of time will start to suck up more and more resources as new elements are constantly being added to the DOM. There is however a fix too it figure out when you’ve looped through to cycle them back to original starting point then no new slides need to be added and it can loop them; visually this is easier to see then to explain
Extra Extra Note:
Another thing I just realized is if you use the technique above then technically you can get rid of the
beforeevent callback and simply generate all the needed slides before you even start the slideshow.