2012-04-21 77 views
-1

我正在创建一个网页,当用户在图像上悬停时,它会显示一个段落,该段落包含在它下面的一个分区中。当用户将光标移出图像时,分区消失。在屏幕上保留一个分区

我的问题是,当用户点击这是在屏幕底部的图像..我想使用JavaScript的直到在底部分割可见滚动页面...

我想知道如何做到这一点。使用哪个函数?

在此先感谢..

+1

让代码自己说话。你的代码在哪里?你有什么尝试? – Joseph 2012-04-21 10:42:22

+0

我试图使用'window.scrollBy(x,y)'函数......但是我真的不知道如何找出屏幕上'div'的位置? – nitish712 2012-04-21 10:48:23

回答

1

基本上你需要计算你的浏览器窗口的高度....然后也知道你的形象的高度,它的偏移量(即在其被放置)...

做一些数学,你会得到额外的页面滚动你想拥有... 只是做...

这里有一些功能,为您提供:

in Internet Explorer (backward-compatibility mode): 
document.body.offsetWidth, document.body.offsetHeight 

in Internet Explorer (standards mode, document.compatMode=='CSS1Compat'): 
document.documentElement.offsetWidth, document.documentElement.offsetHeight 

in most other browsers – as well as IE9 (standards mode): 
window.innerWidth, window.innerHeight (the page's visible width/height) 
window.outerWidth, window.outerHeight (the browser outer width/height) 

请直接从这里取得:http://www.javascripter.net/faq/browserw.htm 您可以在这里查看更具体的例子,了解如何计算所需的参数。

相关问题