Home Articles FAQs XREF Games Software Instant Books BBS About FOLDOC RFCs Feedback Sitemap
irt.Org
#

Q1496 How do I pause a JavaScript animation when clicking on a button?

You are here: irt.org | FAQ | JavaScript | Form | Q1496 [ previous next ]

Try:

<script language="JavaScript"><!--
var stop=true;
var speed = 100;
var tId = '';
function animate() {
   clearTimeout(tId);
   if (stop) return;
// here goes your animation
   tId=setTimeout('animate()',speed);
}
//--><script>

<form>
<input type="button" onClick="stop=!stop;animate(); if (stop) this.value='Start'; else this.value='Stop';return false" VALUE="Start">
</form>

©2018 Martin Webb