Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Function > throttle #19

Open
PunitSoniME opened this issue Jan 11, 2023 · 0 comments
Open

Function > throttle #19

PunitSoniME opened this issue Jan 11, 2023 · 0 comments

Comments

@PunitSoniME
Copy link
Owner

PunitSoniME commented Jan 11, 2023

throttle(func, [wait=0], [options={}])

Arguments

  • func (Function): The function to throttle.
  • [wait=0] (number): The number of milliseconds to throttle invocations to.
  • [options={}] (Object): The options object.
  • [options.leading=true] (boolean): Specify invoking on the leading edge of the timeout.
  • [options.trailing=true] (boolean): Specify invoking on the trailing edge of the timeout.

Returns

  • (Function): Returns the new throttled function.

Example

// Avoid excessively updating the position while scrolling.
jQuery(window).on('scroll', throttle(updatePosition, 100));
 
// Invoke `renewToken` when the click event is fired, but not more than once every 5 minutes.
var throttled = throttle(renewToken, 300000, { 'trailing': false });
jQuery(element).on('click', throttled);
 
// Cancel the trailing throttled invocation.
jQuery(window).on('popstate', throttled.cancel);
@PunitSoniME PunitSoniME added help wanted Extra attention is needed ✨ feature and removed help wanted Extra attention is needed labels Jan 20, 2023
@PunitSoniME PunitSoniME added this to the Remaining Methods milestone Jan 26, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant