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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T11:16:47+00:00 2026-05-27T11:16:47+00:00

I coded for a chat script and all the issue is with scrolling DIV

  • 0

I coded for a chat script and all the issue is with scrolling DIV layer. I downloaded few chat scripts and found the below after careful observation.

When ever a new line of chat is added, scroll bar doesn’t scrolls down after chat line is added. Its adding to the bottom of the DIV layer as the scroll doesn’t make any kind of disturbance while making it.

What I did:

Before I used javascript to scroll down for every fixed interval. Doing this I am unable to manually scroll up to view past lines(due to interval refresh scroll bar moves to set position). Later I coded for a javascript that can scrolls down OnClientClick but doing this I can only able to scroll down Chat sender side but it cannot scroll down at Chat receiver side when a new chat line is added.

I downloaded many chat scripts and checked how this particular issue is managed but I couldn’t find any solution for it. I fairly guess that its the work of jQuery (not sure) can anybody tell me how to fix this issue?

I am sorry if you failed to understand my issue as I am unable to explain it in more detailed than as above. However I can give you more information on request.

Languages I am using are ASP.NET, AJAX update panels, timer ticks for updating div with new values, javascripts are till now used only to scroll down the element.

  • 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-27T11:16:48+00:00Added an answer on May 27, 2026 at 11:16 am

    Your chat ‘screen’ should look like this:

    <div id="chat">
        <div class="wrapper">
            <!-- chat messages go here -->
        </div>
    </div>
    

    Put overflow-y: auto on the chat, but leave the wrapper as it is. Create on function that runs at an interval and add or removes a class “atBottom” to chat ‘screen’ based on value returned by $(‘#chat’).scrollTop() method.

        monitor = function() {
            var $this = $(this),
                wrap = $this.find('.wrapper'),
                height = $this.height(),
                maxScroll = wrap.height() - height,
                top = $this.scrollTop();
            if (maxScroll === top) {
                $this.addClass('atBottom');
            } else {
                $this.removeClass('atBottom');
            }
        }
        window.setInterval(function() {
            monitor.call($('#chat').get(0));
        }, 350);
    

    Then you need to bind an event ‘addMessage’ that works like so:

        $('#chat').bind('addMessage', function(e, message) {
            var $this = $(this),
                // store whether it's at the bottom before appending the message
                scroll = $this.hasClass('atBottom');
            // then append the message
            $this.find('.wrapper').append(message);
            if (scroll) {
                // measure the new maxScroll and scroll to it.
                var wrap = $this.find('.wrapper'),
                    height = $this.height(),
                    maxScroll = wrap.height() - height
                $this.scrollTop(maxScroll);
            }
        })
        $('button').click(function() {
            $('#chat').trigger('addMessage', 'asdgagasdg<br/>');
        });
    

    Here’s an example:
    http://jsfiddle.net/WVLE2/

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

Sidebar

Related Questions

I coded some calculation stuff (I copied below a really simplifed example of what
To scroll down my chat DIV I am using the following code which is
I'm using this code $.post(assets/scripts/chat/load_convos.php,{}, function(data) { $.each(data, function(index, value) { alert(value); }); ,and
I'm trying to implement long polling in a php chat script, however the long
i recently created a custom ping box(chat) for personal needs. When i coded it
I'm making a chat script using jQuery and JSON, but my hosting suspends it
Good day to all. I have an odd error. I have created a chat
Below you see a part of the server-side code of the twich.me node.js chat:
I've written a script that decreases the width of a div if a variable
I have made a chat script using php, mysql and jquery. It uses json

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.