用于设置元素的ScrollTop的跨浏览器方法? [英] Cross-Browser method for setting ScrollTop of an element?

查看:157
本文介绍了用于设置元素的ScrollTop的跨浏览器方法?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

例如,我有一个带有div标签右侧滚动条的div标签。

我想用最后一行显示div,所以我有这个:

For example I have I a div tag with the scroll bar on the right of the div tag.
I want to show the div with the last line, so I have this:

document.getElementById("divscroll").scrollTop = 250000;

我可以让它在Firefox中滚动到最后但从未成功使用数字较大的IE事件!

有没有简单的Cross-borwser脚本(不是JQuery或任何大框架!)

I can make it scroll to the end in Firefox but never succcess with IE event with the bigger number!
Is there any simple Cross-borwser script (not JQuery or any big framework!)

推荐答案

< a href =http://www.quirksmode.org/dom/w3c_cssom.html#t35 =noreferrer> scrollTop 适用于所有主流浏览器。

scrollTop works in all major browsers.

要滚动到元素的底部:

var div = document.getElementById('divscroll');
div.scrollTop = div.scrollHeight - div.clientHeight;

clientHeight 也适用于各种浏览器 scrollHeight 主要是有效。

clientHeight also works across browsers, and scrollHeight mostly works.

这篇关于用于设置元素的ScrollTop的跨浏览器方法?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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