timeout - Mistake in jquery function -


i have jquery timeout function, think made syntax mistakes, can correct me did wrong

i want scroll page after 5 second, if user click on button don't want scroll, here have now, ok when user click don't know how prevent scroll? here example code

$(document).ready(function () {      var clickscroll = 0;      $('.jumper').click(function () {         clickscroll = clickscroll + 1;         $('html, body').animate({             scrolltop: $(".section-one-home").offset().top - 98         }, 2000);       });      if (clickscroll == 0) {         settimeout(function () {             $('html, body').animate({ scrolltop: $(".section-one-home").offset().top - 500 }, 2000);         }, 5000);     }  }); 

any suggestion?

you can using cleartimeout cancel function in settimeout :

$(document).ready(function () {      var clickscroll;      clickscroll = settimeout(function () {             $('html, body').animate({ scrolltop: $(".section-one-home").offset().top - 500 }, 2000);         }, 5000);      $('.jumper').click(function () {         cleartimeout(clickscroll);         $('html, body').animate({             scrolltop: $(".section-one-home").offset().top - 98         }, 2000);     });  }); 

Comments

Popular posts from this blog

javascript - RequestAnimationFrame not working when exiting fullscreen switching space on Safari -

Python ctypes access violation with const pointer arguments -