获取滚动条位置 [英] Get Scrollbar Position

查看:108
本文介绍了获取滚动条位置的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,


我正在设置< div>在一个冗长的页面上的页面上,有大量的

文本。我想让div落在用户可以看到的地方。我需要

捕获垂直滚动条位置并使用该整数设置

div的''Y'坐标。


可以这样做吗?如果是这样,怎么样?


如果没有,还有其他任何建议吗?


谢谢,


杰夫

Hi All,

I''m setting a <div> on a page on a lengthy page with a great deal of
text. I want the div to land where the user can see it. I need to
capture the vertical scrollbar position and use that integer to set
the ''Y'' coordinate for the div.

Can this be done? If so, how?

If not, any other suggestions?

Thanks,

Jeff

推荐答案

:我正在设置一个< div>在一个长页面上的页面上,有很多

:文本。我想让div落在用户可以看到的地方。我需要

:捕获垂直滚动条位置并使用该整数来设置

:div的''Y'坐标。


让x,y为鼠标位置。

让zoom_factor为身体内容缩放的MSIE%



document.body.style.setAttribute(''zoom'',zoom_factor +''%'');

)。

让''contextmenu''成为你的DIV的ID。


xOff = parseInt(document.getElementById(''contenxtmenu'')。s tyle.width) -

(document.all ?document.body.scrollLeft:window.page XOffset);

yOff = parseInt(document.getElementById(''contenxtmenu'')。s tyle.height) -

(document.all?document.body.scrollTop:window.pageY Offset);

document.getElementById(" contenxtmenu")。s​​tyle.top =

Math.min (parseInt(y / zoom_factor * 100),document.body.clientHeight-yOff)+" px" ;;

document.getElementById(& contenxtmenu。)。style.left =

Math.min(parseInt(x / zoom_factor * 100),document.body.clientWidth-xOff)+" px";

然后你的div将被放置在鼠标旁边,但总是完全在屏幕上。

如果你不放大并且不介意鼠标;替换y / zoom_factor * 100

和x / zoom_factor * 100取决于你的优惠y和x位置

< div>在你的页面上。


Wouter
: I''m setting a <div> on a page on a lengthy page with a great deal of
: text. I want the div to land where the user can see it. I need to
: capture the vertical scrollbar position and use that integer to set
: the ''Y'' coordinate for the div.

let x, y be the mouse position.
let zoom_factor be the % in MSIE that the body content is zoomed
(
document.body.style.setAttribute(''zoom'', zoom_factor+''%'');
).
let ''contextmenu'' be the ID of your DIV.

xOff = parseInt(document.getElementById(''contenxtmenu'').s tyle.width) -
(document.all?document.body.scrollLeft:window.page XOffset);
yOff = parseInt(document.getElementById(''contenxtmenu'').s tyle.height) -
(document.all?document.body.scrollTop:window.pageY Offset);
document.getElementById("contenxtmenu").style.top =
Math.min(parseInt(y/zoom_factor*100),document.body.clientHeight-yOff)+"px";;
document.getElementById("contenxtmenu").style.left =
Math.min(parseInt(x/zoom_factor*100),document.body.clientWidth-xOff)+"px";
Then your div will be placed next to the mouse, but always fully on screen.
If you don''t zoom and don''t mind the mouse; replace y/zoom_factor*100
and x/zoom_factor*100 by the prefered y and x location of your
<div> on your page.

Wouter


DJ WIce写道:
DJ WIce wrote:
:I我正在设置< div>在一个长页面上的页面上,有很多
:文本。我想让div落在用户可以看到的地方。我需要
:捕获垂直滚动条位置并使用该整数来设置
:div的''Y'坐标。

让x,y为鼠标位置。
让zoom_factor为身体内容缩放的MSIE%

document.body.style.setAttribute(''zoom'',zoom_factor +''%'');


只有MSIE 5.5和MSIE 6支持缩放。

)。
让''contextmenu''成为你DIV的ID。

xOff = parseInt(document.getElementById(''contenxtmenu'')。s tyle.width) -
(document.all?document.body.scrollLeft:window.page XOffset);


如上所述,你只支持向后兼容的渲染模式

MSIE 6,其中根元素不是正文。您的脚本可能很有趣,但它在当前浏览器中的范围/支持有限。


DU

yOff = parseInt(文档.getElementById(''contenxtmenu'')。s tyle.height) -
(document.all?document.body.scrollTop:window.pageY Offset);
document.getElementById(" contenxtmenu") .style.top =
Math.min(parseInt(y / zoom_factor * 100),document.body.clientHeight-yOff)+" px" ;;
document.getElementById(" contenxtmenu") .style.left =
Math.min(parseInt(x / zoom_factor * 100),document.body.clientWidth-xOff)+" px";

然后你的div将被放置鼠标旁边,但总是完全在屏幕上。
如果你不放大,不要小心鼠标;将y / zoom_factor * 100
和x / zoom_factor * 100替换为
< div>的首选y和x位置在你的页面上。

Wouter
: I''m setting a <div> on a page on a lengthy page with a great deal of
: text. I want the div to land where the user can see it. I need to
: capture the vertical scrollbar position and use that integer to set
: the ''Y'' coordinate for the div.

let x, y be the mouse position.
let zoom_factor be the % in MSIE that the body content is zoomed
(
document.body.style.setAttribute(''zoom'', zoom_factor+''%'');
zoom is only supported by MSIE 5.5 and MSIE 6.
).
let ''contextmenu'' be the ID of your DIV.

xOff = parseInt(document.getElementById(''contenxtmenu'').s tyle.width) -
(document.all?document.body.scrollLeft:window.page XOffset);
As written, you will only support backward compatible rendering mode in
MSIE 6 where the root element is not the body. Your script might be
interesting but it has limited scope/support among current browsers.

DU
yOff = parseInt(document.getElementById(''contenxtmenu'').s tyle.height) -
(document.all?document.body.scrollTop:window.pageY Offset);
document.getElementById("contenxtmenu").style.top =
Math.min(parseInt(y/zoom_factor*100),document.body.clientHeight-yOff)+"px";;
document.getElementById("contenxtmenu").style.left =
Math.min(parseInt(x/zoom_factor*100),document.body.clientWidth-xOff)+"px";
Then your div will be placed next to the mouse, but always fully on screen.
If you don''t zoom and don''t mind the mouse; replace y/zoom_factor*100
and x/zoom_factor*100 by the prefered y and x location of your
<div> on your page.

Wouter



:如上所述,你只支持向后兼容的渲染模式br />
:MSIE 6,其中根元素不是正文。你的脚本可能是

:有趣,但它在当前浏览器中的范围/支持有限。

嗯,它已经在Mozilla 1.3和MSIE 5+中进行了测试......

还有NN 7和MSIE 6

(参见 http://www.djwice.com/contextmenu.html

zoom_factor值默认设置为100,所以当缩放功能

没有实现,它不会被更改,并且位置值保持<​​br />
(几乎)不变。


Wouter
: As written, you will only support backward compatible rendering mode in
: MSIE 6 where the root element is not the body. Your script might be
: interesting but it has limited scope/support among current browsers.
Well, it''s tested in Mozilla 1.3 and MSIE 5+ ...
And also om NN 7 and MSIE 6
(see http://www.djwice.com/contextmenu.html )

The zoom_factor value is default set to 100, so when the zoom function is
not implemented, it will not be changed, and the position values stay
(nearly) unchanged.

Wouter


这篇关于获取滚动条位置的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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