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 6795399
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T18:20:26+00:00 2026-05-26T18:20:26+00:00

I have a div which is constantly streaming data and has functionality allowing it

  • 0

I have a div which is constantly streaming data and has functionality allowing it to automatically scroll to the bottom, putting the latest information in the user’s sights all the time.

However, the problem with my current implementation is that this element does not care if a user wishes to scroll up and see lines which were printed previously. As soon as new data is POSTed, the div pulls the scroller right back to the bottom. Considering updates happen very often (~500 ms), this can be quite irritating to a user who wishes to view the entire log at their own leisure.

Ideally, here’s what I want to do with this div

  • When the user clicks inside the div itself, or the scroll bar (overflow:auto), autoscrolling is immediately disabled.
  • As soon as the user clicks outside, autoscrolling is re-enabled.
  • When the page is first loaded, the div is, by default, set to be not focused (i.e. autoscrolling happens if the user does not click anywhere)

Code:

<script type="text/javascript">
    $(function () {
        $("#testMonitor").everyTime(500, function () {
            $("#testMonitor").attr({ scrollTop: $("#testMonitor").attr("scrollHeight") - $('#testMonitor').height() });
        });
    });        
</script>

<script type="text/javascript">
    $("div#testMonitor").attr("tabindex", -1).focusin(function () {
        $("#testMonitor").attr({ scrollTop: $("testMonitor").height() });
    });
</script>

The first chunk is my auto-scroll, which works as expected. The second part is supposed to set scrollTop to the “normal” height upon onFocus.

How can I modify my focusin function to behave as desired?

  • 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-26T18:20:27+00:00Added an answer on May 26, 2026 at 6:20 pm

    Easier than you might think.

    1) Create a flag

    var autoScrollEnabled = true;
    

    2) Modify your auto scroll to run only when autoScrollEnabled is true

    $(function () {
        $("#testMonitor").everyTime(500, function () {
            if (autoScrollEnabled == true) {
                $("#testMonitor").attr({ scrollTop: $("#testMonitor").attr("scrollHeight") - $('#testMonitor').height() });
            }
        });
    });
    

    3) Add code to toggle auto scroll wherever appropriate

    toggleAutoScroll();
    
    function toggleAutoScroll() {
        autoScrollEnabled = !autoScrollEnabled; //! reverses the value, true becomes false, false becomes true
        if (autoScrollEnabled == true) { //scroll down immediately if a.s. is reenabled
            $("#testMonitor").attr({ scrollTop: $("#testMonitor").attr("scrollHeight") - $('#testMonitor').height() });
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a div which has style properties as border-top, left, right, bottom set.
I have a menu div which has a dark background. Inside it, I have
I have a div which has width of say 200px. It does not show
I have a relatively -positioned div, which has overflow: auto set. Inside that, I
Here is my situation, I have a div which has height:400px and overflow:auto to
I have DIV which has 2 backgrounds, in my case, it is gradient and
I have a div which appears when a textbox gets focus. DIV has n
I have a div which has no content. the content is dynamically loaded into
I have a div which I have attached an onclick event to. in this
I have a div which displays the current value of the slider and the

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.