![]() |
Stop setInterval
I have 2 questions about setInterval. I hope someone has the answer especially on my second question, which i spent a lot of time on..
1. I want setInterval to make tha animation to loop on page load. I'm using <body onLoad="pulseStart()"> which works fine. But as soon as i insert the line $(document).ready(function() {}); , the body onload stops working. I have been told that a JQuery must always start with "document ready", is that wrong?2. I'm using "onClick" on a div in body to stop the animation. This works, but for some reason the animation keeps looping for a number of times; the longer i wait after page load, the more times the animation will run before stopping. How can i stop the animation immediatly? Here is the code: Code:
HTML |
OK, you’re mixing a lot of things up here. First of all you need to understand what jQuery is and why and when to use it. Having no idea about the tools you are using doesn’t help you achieve what you intend. The documentation gives a good start.
Now, when you use jQuery you don’t need any <body onload="…"> crap. If you already include that much overhead code (even in its minfied form jQuery is still 32KB of code) with a lot of prefabricated functionality to ease development why not use it then? Put all your functions into the “document ready” function of jQuery and there you go. And by the way: A shorthand way to write $(document).ready(function() {…}); is to just write $(function() {…});; it does the same.Then, you are doing it much more complicated than you need to. You have jQuery, remember? You can and should use the callback functions animate() provides to run functions recursively. Then, jQuery also has the stop() function to stop animations at any time.Something like this: Code:
<div id="example"></div>Code:
#example {PHP Code:
|
JavaScript statements (other than compound) are terminated with a semi-colon.
Your code sample(s) appear to have a missing closing bracket for pulse(). Use jQuery's stop() to stop an animation. Code:
var timerId; |
| All times are GMT +1. The time now is 12:10 PM. |
Powered by vBulletin®
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.