Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7186349
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T18:36:45+00:00 2026-05-28T18:36:45+00:00

I’m looking for a simple & semantic way to code jQuery event handlers that

  • 0

I’m looking for a simple & semantic way to code jQuery event handlers that allow a reasonable timeout or other way of ‘slowing’ down the rate at which events are fired, in order to prevent the user from spamming (on purpose or inadvertantly) my handlers.

This isn’t usually a concern for me personally as in most cases simply halting the operations of the previous handler is enough – example being a fading menu; simply using .stop() on the animations is good enough.

However I’m now building a much more js heavy page whose events are simply too expensive to fire off more than once or twice a second, and with multiple ways of firing those events I find myself needing to limit how often they will execute at a more base level.

An example of the problem:

$(document).bind('mousewheel', function(e, delta){
    alert('you scrolled the mousewheel!');
    stopLoadsOfStuff();
    fadeHalfADozenImagesInAndOutAgain();
});

I’m using the mousewheel plugin (here: http://brandonaaron.net/code/mousewheel/docs) as depending on mouse, OS or manufacturer supplied software, the scroll rate can vary wildly. Think one of those shiny apple touch mice vs an old ball mouse from the 90s. If you fire an event on scroll, you will find that you need to limit it to something sensible unless your event is very cheap to execute and stop.

Things I’ve already tried are:

For clicks and keyboard events:

setting a boolean for each event, setting it to true while the event fires and using a callback to set it to false again. Event only executes if bool is false.
This worked, but is messy and a little too specific.

For mousewheel events:

I increment an integer variable each time a mousewheel event is detected, and only take action if it’s more than 5. The handler resets it to 0 on execution.

tl;dr

I need an extendable, simple way to limit the rate of execution of event handlers which will allow me to use expensive event handlers without worrying about the user attempting to execute them 100 times a second 🙂

Any help appreciated

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-28T18:36:47+00:00Added an answer on May 28, 2026 at 6:36 pm

    You may be interested in the jQuery debounce plugin.

    The concept behind the plugin is that it wraps the handler you pass in another function, which rate limits the execution of the function by only calling it every x milliseconds.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
I have a jquery bug and I've been looking for hours now, I can't
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I have just tried to save a simple *.rtf file with some websites and
I've got a string that has curly quotes in it. I'd like to replace
Seemingly simple, but I cannot find anything relevant on the web. What is the
I have a French site that I want to parse, but am running into
I have this code: - (void)parser:(NSXMLParser *)parser foundCDATA:(NSData *)CDATABlock { NSString *someString = [[NSString

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.