Function throttling: Just like the Chengdu Lottery to buy a house, the first to go to choose a room, the next one will wait a while. This strategy is a good solution, a large wave of people go into the room, sales sister did not send the embarrassing situation of reception.
Scenario: Listen for the browser scroll bar and then trigger the function.
Common practice document.getElementById ("throttle"). onscroll = function () { //monitor to hear the scrolling directly triggered, continuous scrolling will trigger the callback (); };/ /function Throttle var canrun = True;document.getelementbyid ("throttle"). onscroll = function () { //By setting the lock, for a period of time only a sister paper came in, too much to cope with, You know:) if (!canrun) { return; } Canrun = false; SetTimeout (function () { console.log ("Functions throttle"); Canrun = true; }, 300);};
Function anti-jitter: Just like choosing a sister, came a queue sister let you choose, you only choose the last one, because the front is too ugly.
Application scenario: Input Set the onchange event, once changed, it will trigger the change event, keep changing, will be triggered. In fact, we only need the last value entered.
JS function throttling and anti-jitter