problem about debouncing-Collection of common programming errors


  • alexej_d
    jquery performance scrolling requestanimationframe debouncing
    I have written a plugin for my personal homepage, which is supposed to scroll through a series of elements, snapping to each elements offsetTop. I am using requestanimationframe to debounce the scrolling events but sometimes slides are being skipped and I just can’t figure why. Additionally on Chrome and Safari I have the problem that window.pageYOffset can be smaller than 0 and bigger than document hight because of some kind of easing those browsers are using on mac (with the touchpad) – how would you handle that?Here is the Code:// requerstanimationframe for all browsers window.rAF = (function(){return window.requestAnimationFrame || window.webkitRequestAnimationFrame || window.mozRequestAnimationFrame || window.oRequestAnimationFrame || window.msRequestAnimationFrame || function( callback ){window.setTimeout(callback, 1000 / 60);};})();// main plugin code var Slides = {el: “.slide”,arrowUp: $(“.btn-previous”),arrowDown: $(“.btn-next”),lastSlide: 0,lastY: 0,scrolling: false,scrollSpeed: 500,init: function(){this.$elem = $(thi

Originally posted 2013-11-06 03:09:13.