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

  • Home
  • SEARCH
  • 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 898501
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T15:03:12+00:00 2026-05-15T15:03:12+00:00

i was wondering what was the use of setting setTimeout to a variable scroll_timer

  • 0

i was wondering what was the use of setting setTimeout to a variable

scroll_timer = window.setTimeout(function () { ... 

when i can just use

window.setTimeout(function () { ... 

and is there a need to clearTimeout actually? line 2

$window.scroll(function () {
    window.clearTimeout(scroll_timer);
    scroll_timer = window.setTimeout(function () { // use a timer for performance
        if($window.scrollTop() <= top) // hide if at the top of the page
        {
            displayed = false;
            $message.fadeOut(500);
        }
        else if(displayed == false) // show if scrolling down
        {
            displayed = true;
            $message.stop(true, true).show().click(function () { $message.fadeOut(500); });
        }
    }, 100);
});

code from scroll to top in jquery

  • 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-15T15:03:12+00:00Added an answer on May 15, 2026 at 3:03 pm

    In the given example the effect is to “reset” the timeout.

    Since the scroll event can be fired many times, you would end up with many duplicate messages displayed after a tenth of a second. If a second scroll event is called before the first one has run, we cancel the first one and set a new timeout to start a tenth of a second after the latest scroll event.

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

Sidebar

Related Questions

Im creating a WPF application and just wondering is there a way to use
I was wondering if I use PHP's hash() function to generate sha512 hashes how
I was just wondering on the most efficient way of setting inherited members was
I am setting up a simple has_many through relationship. I was wondering if there
These are mainly just some things I've been wondering, maybe someone can give me
I came across the function InterlockedExchange and was wondering when I should use this
I was wondering is there any clear advantage of setting some cookie though JavaScript
There has been a post about setting cron job to index: Use a Cron
I wondering whether use a webView to create a complex text area done with
Studying compilers course, I am left wondering why use registers at all. It is

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.