我的网站中有DIV
,其高度不固定。当用户在图像上移动鼠标时,将出现DIV
,并显示有关图像的一些信息。页面上有几个网格格式的图像,每个图像都有自己的信息。很明显,一些图像位于屏幕底部,因此mouseover
信息的某些部分DIV
将不在屏幕上。我想自动控制这种情况,当其DIV
的任何部分离开屏幕时,滚动条会一直向下,直到它到达DIV
的底部。
这是我的伪代码但我无法在jquery中实现它。
screenHeight
divHeight
divDistanceFromTopOfScreen
如果(screenHeight
< divHeight
+ divDistanceFromTopOfScreen
)那么
scroll down to bottom of `DIV`
如果你认为这个算法是对的,我怎么能实现这个呢?
答案 0 :(得分:-1)
这应该这样做。
<强>使用Javascript:强>
var top = $('.theDiv').offset().top; // the top of your div relative to the document
var div_height = $('.theDiv').height(); // the height of your div
window.scrollTo(0, top + div_height); // scroll to the bottom of your div
<强>参考文献:强>