jquery advance on ideltimeout
I am sure there is some jQuery wiz out there that can do that in 5-6 line开发者_Python百科s... my code look more like spaghetti now, so that why i ask here
I have about 20 sideshow on a page with <prev
andnext>
buttons
i like on any 1 sec to execute a click on any next sideshow on random
Do it will be lees distraction, that having 20 sideshow auto advance all at once...
How do you do that with jQuery
on every 1 second, select any class=next (button) and click()
--
just for the record : that dont work !
<script type="text/JavaScript">
jQuery(document).ready(function($) {
setInterval( $('.next').click(), 1000 );
});
</script>
Pass a function to setInterval
.
jQuery(function($) {
var $next = $('.next'); // cache the selector for better performance
setInterval(function () {
$next.click();
}, 1000 );
});
If you want to randomly pick just one of the '.next'
to click:
jQuery(function($) {
var $next = $('.next'),
n = $next.length;
setInterval(function () {
$next.eq(Math.floor(Math.random()*n)).click();
}, 1000 );
});
精彩评论