jquery - Stop a setInterval function -
When I switch the button "STOP" and click, I try to set this interlabel function I am here. The word START is changing in STOP and vice versa, but the random BG color change will not stop and instead it will be compound.
$ (document) .ready (function () {function randomColor () {return "#" + Math.random () .toString (16) .Slice (2,8);} $ ("Button"). Click (function () {var $ go = $ ("button") .txt (); if ($ go === "START") {setInterval (function color () ($ ( "CSS" ("background color", "white") $ ("button") ("button") ("body"). CSS ("background color", random collar ());}, 300) Stop ");} Other {// tried a clean interval and are doing a new $ (" body "). Text (" Start ");}}});}); Please let me know if any link or additional information is helpful on the site Gee. Thanks!
you the value returned by setInterval in a code save will, and when it would like to turn it off to the clear intervals : var timer; ($ Go === "START") {timer = setInterval (function View () {$ ( "body"). css ( "background-color" random caller ());}, 300); $ ( "button"). text ( "pause");} other {Clear interval (timer); $ ("Button") .text ("START");};});
Comments
Post a Comment