开发者

jquery advance on ideltimeout

开发者 https://www.devze.com 2023-02-26 23:05 出处:网络
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 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 <prevandnext> 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 );
});
0

精彩评论

暂无评论...
验证码 换一张
取 消