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

Popular posts from this blog

Verilog Error: output or inout port "Q" must be connected to a structural net expression -

jasper reports - How to center align barcode using jasperreports and barcode4j -

c# - ASP.NET MVC - Attaching an entity of type 'MODELNAME' failed because another entity of the same type already has the same primary key value -