views:

174

answers:

2

Hi 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 +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

A: 

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);
Keith Morgan
A: 

You can just trigger the click event:

var timer = setInterval(function() { jqimg.click(); }, 5000);
Greg
but the jqimg.click() function is in the jqgalscroll.js plugin
michael
That doesn't matter, though you may need to get the handle to jqimg yourself - instead of `jqimg.click();` it would be `$('#something').click();`
Greg