Jump to content

Recommended Posts

So i'm trying to make a play/pause toggle button for a slideshow gallery I'm making right. When turned on the slideshow should perfoerm the function goForward() every 5000ms. I can successfully start the interval but when trying to clear it all it seems to do is start the interval again and create a new set of intervals so my images start scrolling twice as fast.

 

LINKSAUS: http://www.lojiki.com/slider/

 

$("#play-pause-button").click(function(){
if(timer == null){
	var timer = setInterval(goForward, 5000);
	$("#play-pause-button").html("<img src='http://www.rogercpareview.com/media/images/layout/play-iconB2_small.png'>").load(function(){
		$("#play-pause-button").val("on");
	});
return false;
};
if(timer != null){
	clearInterval(goForward);
	var timer = null;
	$("#play-pause-button").html("<img src='http://www.spalook.com/resources/assets/product/player_pause_button.jpg'>").load(function(){
		$("#play-pause-button").val("off");
	});
};	
});

clearInterval() needs the timer to stop it, not the code to execute. Including a couple other fixes,

$("#play-pause-button").click(function(){
var timer = null;
if(timer == null){
	timer = setInterval(goForward, 5000);
	$("#play-pause-button").html("").load(function(){
		$("#play-pause-button").val("on");
	});
} else {
	clearInterval(timer);
	timer = null;
	$("#play-pause-button").html("").load(function(){
		$("#play-pause-button").val("off");
	});
}
return false;
});

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.