Chrome works, every time you slide the scroll wheel, alert 1,2,3,4,5,6 ... And Firefox will be inexplicably executed many times, the first alert will output unequal values!
无标题文档
Refer to this article, turn off Firefox smooth scrolling, but if the wheel slide faster, there will be problems. Http://mozilla.com.cn/forum.phpmod=viewthread&tid=35551&highlight=Scroll
Reply content:
Chrome works, every time you slide the scroll wheel, alert 1,2,3,4,5,6 ... And Firefox will be inexplicably executed many times, the first alert will output unequal values!
无标题文档
Refer to this article, turn off Firefox smooth scrolling, but if the wheel slide faster, there will be problems. Http://mozilla.com.cn/forum.phpmod=viewthread&tid=35551&highlight=Scroll
throttledebounce
Requestanimationframe + customevent
;(function() { var throttle = function(type, name, obj) { obj = obj || window; var running = false; var func = function() { if (running) { return; } running = true; requestAnimationFrame(function() { obj.dispatchEvent(new CustomEvent(name)); running = false; }); }; obj.addEventListener(type, func); }; /* init - you can init any event */ throttle ("scroll", "optimizedScroll");})();// handle eventwindow.addEventListener("optimizedScroll", function() { console.log("Resource conscious scroll callback!");});
Original