VS image stabilization function expansion function

(1) anti-shake function debounce

After the stop function triggered a period of time (no longer trigger during debounce, or they will re-timing), and then execute the callback function

mechanism:

The main anti-shake function using the delay timer execution characteristics, depending on whether there is a timer to perform in waiting:

  • After a trigger event: If there is a regular task to be performed, the timer is cleared, re-timing.
  • If there is no task to be executed, the timing of the implementation of this event.

# Scenarios:

  1. Click on the continuous form, prevent duplicate submission. Such as repeatedly sending an article.
  2. Class Baidu search, continuous input and other input stops after the search.
  3. Drag the browser window, just want to trigger an event and so on.

 

 

(2) throttle the throttling function

A specified unit of time, within this unit time, only one trigger event callback execution (per unit of time has been repeatedly triggered the event, to take effect only once). 
Throttling function at a given time (gapTime) to decide whether to trigger a callback based on the time difference exceeds.

Scenario:

  1. Auto save draft feature, when (the triggering event has been) a user input, the unit of time only saves drafts.
  2. Game refresh rate

 

 

(3) Comparative

The role and nature:

  • Anti-shake function and throttle function is mainly to solve the problem is: to prevent the function of "short-term" Repeat.

  • Which are essentially: the number of execution of the function control on the timeline.

# Application instance, you need to add in parentheses:

Because the return debounceand throttlethe return is a function, so if the event is not executed automatically monitor callback, then we should add behind (), execution returns to the closure function.

 

 

 

 

.

Guess you like

Origin www.cnblogs.com/jianxian/p/12079502.html