cubiq/SwipeView

No stop function

chrisafennell opened this issue · 7 comments

I've setup SwipeView to autoplay using SetInterval and next() function. Once autoplay starts... I can't figure out what function to use to stop the autoplay. I tried creating a new function with this.directionX = 0 and this.x = 0 but that doesn't seem to work correctly. It makes the swipe reverse instead of stopping it. Any ideas or advice would be greatly appreciated.

Use clearInterval. Eg:

var timer = setInterval(..., 2000);
...
clearInterval(timer);

Thanks a million Matteo. Incredible script!

@chrisafennell i would be love to know how to move automatically through images! can you share your script please?

setInterval(function(){
gallery.next();
},2000)

Thats exactly what I use.

and to stop it? (im a js noob plus i cant decide what event should stop
it.. navigating? if touching could pause it, that would be sick!

On 10 October 2012 15:53, chrisafennell notifications@github.com wrote:

Thats exactly what I use.


Reply to this email directly or view it on GitHubhttps://github.com//issues/24#issuecomment-9305846.

This is the code I'm currently using. What it does is autoplay the SwipeView if the mouse hasn't moved for a certain length of time. Hope this helps.

var timer = null;
var prevX = 0;
var prevY = 0;
var flip = null;

slidernext = function() {
slider.next();
}

timeoutTrigger = function() {
// Autoplay Slider
flip = setInterval(function() { slidernext(); }, 7500);

}

compareCoords = function(coord, value) {
return coord != value;
}

$(window).mousemove(function(event) {
x = compareCoords(prevX,event.clientX);
y = compareCoords(prevY,event.clientY);
if (!x && !y) {
return;
}
prevX = event.clientX;
prevY = event.clientY;
clearInterval(flip);
clearInterval(fullAds);
clearTimeout(timer);
timer = setTimeout( function() {
timeoutTrigger();
}, 30000 );
});