Image stabilization function

You can reduce HTTP requests with optimizations such as anti-jitter Debounce;

Here’s an example of a scrollbar event: the anti-chattering function onscroll fires once at the end, delaying execution

function debounce(fun,wait){ let timeout return function(){ let content = this let args = arguments if(timeout){ clearTimeout(timeout) } timeout = setTimeout(()=>{ fun.apply(content,args) },wait) } } window.onscroll = Debounce (function(){console.log(' I just execute once ')},5000)

Throttling function

Only a function is allowed to execute once in N seconds. When the interface is invoked by the scroll bar, throttle and other optimizations can be used to reduce HTTP requests.

Function throttle(fn, delay) {let prevTime = date.now (); return function() { let curTime = Date.now(); If (curtime-prevtime delay) {fn. Apply (this, arguments); prevTime = curTime; }}; } // Using var throttle = throttle(function() {console.log(' I just did it once ')}, 1000); window.onscroll = throtteScroll;