javascript - Delay mousewheel function -


i'm using mousewheel , waypoints plugin scroll sections of page; problem having when scroll using apple mighty mouse scrolling sensitive , function gets triggered more once when animation complete. tried set timeout function , variable check if animation complete neither of these worked.

i replicate effect similar 1 on website.

jquery

  $('body').mousewheel(function(event, delta, deltax, deltay) {    cleartimeout(interval);    console.log('test');      $('section').waypoint(function(direction){       thisid = $(this);     },{ offset: '350' });      indexpos = thisid.index('section');      if (completed == true) {       completed = false;        var interval = "";       if (delta > 0) {           interval = settimeout(function(){             if ($(this).not(":first-child")) {                //$(this).animate(function(){                   $('html, body').stop().animate({                       scrolltop: thisid.prev().offset().top - 200                   }, 1000, 'swing' , function() { completed = true; });                 //});             }else {               $('html, body').stop().animate({                       scrolltop: thisid.offset().top - 200                   }, 1000, 'swing' , function() { completed = true;  });             }           },400);         }       else if (delta < 0) {         interval = settimeout(function(){         if ($(this).not(":first-child")) {              $('html, body').stop().animate({                   scrolltop: thisid.next().offset().top - 200               }, 1000, 'swing' , function() { completed = true; });           }           else {             $('html, body').stop().animate({                   scrolltop: thisid.offset().top - 200               }, 1000, 'swing' , function() { completed = true;  });           }           },400);       }      };                        return false; // prevent default    }); 

i don't know doing: indexpos = thisid.index('section'); before doing anything, check if ins't in progress already:

$('body').mousewheel(function(event, delta, deltax, deltay) {     if($('html').is(':animated') || $('body').is(':animated')) return false;     // else, stuff... }); 

Comments

Popular posts from this blog

c# - Send Image in Json : 400 Bad request -

jquery - Fancybox - apply a function to several elements -

An easy way to program an Android keyboard layout app -