I'm trying to add a timer to the jqgalscroll plugin, the plugin has the function
jqimg.click(function(){
var next = n.index + 1;
if((n.index +开发者_C百科1) == el.totalChildres) {
el.pagination.find('[href$=0]').click();
}
else {
el.pagination.find('[href$=#'+ next+ ']').click();
}
});
this is used to move to the next image in the gallery, but im not sure how i would go about calling it from the setInterval function that i have setup in my own page. any help would be appreciated
You can just trigger the click event:
var timer = setInterval(function() { jqimg.click(); }, 5000);
You just pull your code into a function and use it in two places:
var myAction = function(){
var next = n.index + 1;
if((n.index +1) == el.totalChildres) {
el.pagination.find('[href$=0]').click();
}
else {
el.pagination.find('[href$=#'+ next+ ']').click();
}
}
jqimg.click(myAction);
setInterval(myAction, 5000);
I added this to index.html inside script tags. Does the trick. "i" is the link href
var i = 0;
var timer = setInterval(function() {
$('a[href="#'+i+'"]').click();
i++;
if(i == 6){
i = 0;
}
}, 5000);
精彩评论