jQuery 中的同步滑动和滚动
我正在开发一个包含 Ajax 聊天的应用程序。新消息会附加到聊天窗口的底部,该窗口下方有一个文本框和按钮,允许用户发送新消息。每个新行都使用 jQuery Slide() 附加在该行内容(在我的例子中是 ap 元素)上的动画内容中。
页面充满消息后,用户必须不断向下滚动才能看到新消息和文本框。我想通过在附加新消息时自动向下滚动来为用户省去麻烦。
我可以在 Slide() 之后使用 animate() 来实现此目的,如下所示:
newRow.find("p").slideDown();
$('html, body').animate({
scrollTop: $('#Bottom').offset().top
});
它有效,但结果有点不稳定。关于如何使幻灯片和动画协同工作以使整体动画流畅有什么建议吗?
编辑:您可以在 http://jsfiddle.net/tzA4d/1/< 处看到它的工作原理并进行使用。 /a>.等待几秒钟,直到消息到达屏幕底部,您会看到不太平滑的滚动。
I'm working on an application that includes Ajax chat. New messages get appended to the bottom of the chat window, under which there is a textbox and button allowing the user to send new messages. Each new row is appended in an animated matter using jQuery slide() on the content of the row (in my case, a p element).
After the page has filled with messages, the user keeps having to scroll down in order to see new messages and the textbox. I would like to save the user the trouble by automatically scrolling down while appending new messages.
I'm able to achieve this using animate() just after the slide() as per below:
newRow.find("p").slideDown();
$('html, body').animate({
scrollTop: $('#Bottom').offset().top
});
It works, but the result is somewhat jumpy. Any advice on how to make the slide and animate work together so that the overall animation is smooth?
EDIT: You can see it working and play around with it at http://jsfiddle.net/tzA4d/1/. Wait a few seconds until the messages reach the bottom of the screen and you'll see the not-so-smooth scrolling.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您可以在动画“step”回调函数中设置scrollTop
You can make scrollTop in the animate "step" callback function