Javascript listen for 2nd click -
i have script using.i when user clicks once changes var 0 when user clicks again changes var 3 , repeats. click again 0 3 @ moment part want detect 2nd click 'mousemove'.can please below code.
window.addeventlistener('load', function () { function go() { = < height ? + step : 1; m.style.margintop = -i + 'px'; } var = 0, step = 3, space = ' '; var m = document.getelementbyid('marquee'); var t = m.innerhtml; m.innerhtml = t + space; m.style.position = 'absolute'; var height = (m.clientheight + 1); m.style.position = ''; m.innerhtml = t + space + t + space + t + space + t + space + t + space + t + space + t + space; // first click m.addeventlistener('click', function () { step = 0; }, true); // second click m.addeventlistener('mousemove', function () { step = 3; }, true); var x = setinterval(go, 50); }, true);
one approach set click counter. if click counter set step zero, if odd set 3.
var clickcounter = 0; m.addeventlistener('click', function () { step = (clickcounter++ % 2 === 0 ? 3 : 0); }, true);
demo: http://jsfiddle.net/byrkfvvk/
another approach have internal property use boolean toggle.
document.getelementbyid('button').addeventlistener('click', function () { this.active = !this.active; step = (this.active ? 3 : 0); }, true);
Comments
Post a Comment