jquery - Temporarily disabling javascript function from repeating after mouseleave -


i have image gallery rotates through rotator class divs on www.creat3dprinters.com pauses on mouseenter , fires again 1 second after mouseleave.

however, if user moves mouse in , out of rotator class div function calls stack , visible changes until 'stack' completed.

i want 1 second delay has not been completed cancelled on 2nd , subsequent mouseenter not happen.

i have tried using cleartimeout within mouseenter function not seem work.

i know there stop() function did not work either.

any suggestions appreciated.

jquery(document).ready(function () {     var initlist = setinterval('rotateit()', 4000);      $('.rotator').mouseenter(function () {         clearinterval(initlist);     }).mouseleave(function () {         timeout = settimeout(function () {             rotateit()         }, 1000);         initlist = setinterval('rotateit()', 4000);     }) });    function rotateit() {     cleartimeout(timeout);      if ($('#rotator-visible').next('.rotator').length == 0) {         $('.rotator:first').attr('id', 'rotator-visible');         $('.rotator:last').removeattr("id");      } else {         $('#rotator-visible').removeattr("id").next('.rotator').attr("id", "rotator-visible");     } } 

if user moves mouse in , out of rotator class div function calls stack up

then cleartimeout - , in place, not in delayed rotateit. simplest solution call cleartimeout every time before settimeout, can sure there 1 active timeout @ once.

jquery(document).ready(function($) {     var initlist = setinterval(rotateit, 4000),         delay = null;      $('.rotator').mouseenter(function(e) {         clearinterval(initlist);     }).mouseleave(function(e) {         cleartimeout(delay);         delay = settimeout(function () {             rotateit();             initlist = setinterval(rotateit, 4000);         }, 1000);     }) });  function rotateit() {     if ($('#rotator-visible').next('.rotator').length == 0) {         $('.rotator:first').attr('id', 'rotator-visible');         $('.rotator:last').removeattr("id");     } else {         $('#rotator-visible').removeattr("id").next('.rotator').attr("id", "rotator-visible");     } } 

Comments

Popular posts from this blog

linux - Does gcc have any options to add version info in ELF binary file? -

android - send complex objects as post php java -

charts - What graph/dashboard product is facebook using in Dashboard: PUE & WUE -