在页面加载滚动DIV顶部然后设置滚动到正常工作 [英] Scroll div top on page load then set scroll to work normally

查看:214
本文介绍了在页面加载滚动DIV顶部然后设置滚动到正常工作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个聊天系统在我的网站和拖欠消息DIV位置,始终显示在页面加载的最后一条消息。我用下面一行的code做到了这一点:

I have a chat system on my site and defaulted the message div position to always display the last message on page load. I accomplished this by using the following line of code:

  msgDiv = document.getElementById('message_row_large');
  msgDiv.scrollTop = msgDiv.scrollHeight;

然而,这code设置滚动位置等于DIV高度在任何时候,它不允许用户滚动,看看其他消息。

However, this code sets the scroll position to be equal to the div height at all times, which doesn't allow users to scroll up and see other messages.

我需要在页面加载后重新启用滚动到它的默认功能。欢迎任何帮助。

I need to re-enable scroll to its default functionality after the page loads. ANy help is welcome.

感谢您!

P.S。我使用Ajax加载的聊天信息。当用户点击一个名字左边面板上,他的聊天/她和其他人的负载右侧面板上。

P.S. I am using ajax to load chat messages. When user clicks on a name on the left hand panel, the chat between him/her and the other person loads on the right hand panel.

推荐答案

尝试

    $display = $('#message_row_large');
    $display.animate({scrollTop: $display[0].scrollHeight }, 'fast');

工作小提琴:

Working Fiddle:

https://jsfiddle.net/cshanno/3bo48dxj/1/

这篇关于在页面加载滚动DIV顶部然后设置滚动到正常工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆