javascript - How can i make a switch button that each click it will do something else? -



javascript - How can i make a switch button that each click it will do something else? -

i'm calling function within button onclick event:

function pauseslide() { clearinterval(sint); setinterval(slideupdate, 1000); paused(clearinterval) }

and want on first click clearinterval(sint); , if click on button 1 time again setinterval(slideupdate, 1000);

like switch.

in csharp illustration this: celsiusfahrenheit = !celsiusfarenheit; 1 click boolean celsiusfahrenheit true , next click it's false 1 time again true , on....

this javascript button onclick event:

var slideshow = d.getelementbyid('slideshow'), slidecounter = make('div', false, {id: 'slidecounter'}), slidecontrols = make('div', false, {id: 'slidecontrols'}), slideprev = make('a', 'previous slide', { onclick: function (e) { controlevent(e, prevslide); }, classname: 'previous', href: '#' }, slidecontrols), slidenext = make('a', 'next slide', { onclick: function (e) { controlevent(e, nextslide); }, classname: 'next', href: '#' }, slidecontrols), slidepause = make('a', 'pause slide', { onclick: function (e) { controlevent(e, pauseslide); }, classname: 'pause', href: '#' }, slidecontrols)

i did if click pause slide button phone call function pauseslide , within pauseslide want create switch 1 click phone call clearinterval click phone call setinterval.

i have function also:

function slideupdate() { if (swapcounter--) showcounter(); else nextslide(); }

and if click button lot it's making countdown move faster each time.

if help or needed finish code buttons events:

js

there few ways this. best maintain boolean variable such "ispaused" , flip , forth needed. wrap click logic in conditional dependent on variable.

btw can't observe whether interval running or has been cleared. if could, harder read , understand going on. i'd prefer semantic variable described above.

javascript

Comments

Popular posts from this blog

Delphi change the assembly code of a running process -

json - Hibernate and Jackson (java.lang.IllegalStateException: Cannot call sendError() after the response has been committed) -

C++ 11 "class" keyword -