|
蓝森林 http://www.lslnet.com 2006年8月25日 8:28
javascript如何取得滚动条得值。。
[html]
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<title>无标题文档</title>
</head>
<body>
<script language="javascript">
function get() {
alert(document.body.scrollTop);
}
</script>
<p>1</p>
<p>2</p>
<p>3</p>
<p>4</p>
<p>5</p>
<p>6</p>
<p><a href="javascript:get();">取得滚动条顶部得值</a></p>
<p>8</p>
<p>9</p>
<p>0</p>
<p>-</p>
<p>0</p>
<p>9</p>
<p>8</p>
<p>7</p>
<p>7</p>
<p>6</p>
<p>5</p>
<p>4</p>
<p>3</p>
<p>3</p>
<p>2</p>
<p> </p>
</body>
</html>
[/html]
将滚动条拉到中间,点击后,取得的值怎么还是0?
要取得滚动条顶部距离页面顶部的位置,该怎么写呢? |
嘿嘿。。我查到了
把document.body.scrollTop
换document.documentElement.scrollTop;
就好了。。
|
|