Jump to content
Killersites Forums

How do I stop Autoplay after 1 loop


Recommended Posts

I am using a fade transition which I have set to auto loop, but I would like it to stop after one loop. What do I need to change or add to the following JS. I have tried lots of different things but nothing has worked for me so far. Thanks for any help.

 

// autoplay
var autoPlayTimer;
function restartPlay(){
	stopPlay();

	if (options.autoPlay)
		autoPlayTimer = setTimeout(function(){
				go(curIdx<elementsCount-1? curIdx+1: 0);
				restartPlay();
			}, 
			options.delay + options.duration
		);
};
function stopPlay(){
	if (autoPlayTimer) clearTimeout(autoPlayTimer);
	autoPlayTimer = null;
};

function forceGo(event, index){
	stopPlay();
	event.preventDefault();
	go(index)
	restartPlay();		
}

Link to post
Share on other sites

Stef, that sounds really simple for someone who understands the language, but could you possibly explain that in English or preferably Javascript to me?

 

JS is like Chinese to me, I don't speak or write it and am just barely able to implement it. My brain doesn't work that way unfortunately (even after several courses) although I am fluent in several human languages.

 

But thank you for your time and for replying.

Link to post
Share on other sites

Perhaps you can post the full code that you are using, or a include a link (or PM it to me directly) so I can see the page in action? It seems a little silly to have this autoloop functionality if you only need it to loop once. I'm betting the entire javascript could be rewritten to be a lot simpler, but I can't really tell with this small snippet.

Link to post
Share on other sites

Stef, that sounds really simple for someone who understands the language, but could you possibly explain that in English or preferably Javascript to me?

 

JS is like Chinese to me, I don't speak or write it and am just barely able to implement it. My brain doesn't work that way unfortunately (even after several courses) although I am fluent in several human languages.

 

But thank you for your time and for replying.

 

Ooops, sorry about that. Do you want a copy of the Javascript basics course? Let me know ... better yet, do you have a subscription to the killer video library? Let me know I will set it up.

 

Since Ben is on it, I will leave it to Ben.

Link to post
Share on other sites

Perhaps you can post the full code that you are using, or a include a link (or PM it to me directly) so I can see the page in action? It seems a little silly to have this autoloop functionality if you only need it to loop once. I'm betting the entire javascript could be rewritten to be a lot simpler, but I can't really tell with this small snippet.

 

Yep ... I agree. I just wasn't sure if you had some nuanced scenario that I was not considering - basically, you don't need to run a loop if the action has to executed only once. Loops are for repeating something many times.

 

Stefan

Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  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.

Loading...
×
×
  • Create New...