Javascript 如何滚动设置屏幕底部的DIV底部(监视器)
我的网站上有一个Javascript 如何滚动设置屏幕底部的DIV底部(监视器),javascript,html,Javascript,Html,我的网站上有一个DIV,它的高度不是固定的。当用户在图像上移动鼠标时,将显示此DIV,并显示有关图像的一些信息。页面上有几个网格格式的图像,每个图像都有自己的信息。显然,一些图像位于屏幕底部,因此通过mouseoverDIV部分信息将离开屏幕。我想自动控制这种情况,当它的DIV的任何部分离开屏幕时,滚动条就会下降,直到它到达DIV的底部 这是我的伪代码,但我无法在jquery中实现它 计算屏幕高度 计算divHeight 计算距离TopofScreen的距离 如果(屏幕高度
DIV
,它的高度不是固定的。当用户在图像上移动鼠标时,将显示此DIV
,并显示有关图像的一些信息。页面上有几个网格格式的图像,每个图像都有自己的信息。显然,一些图像位于屏幕底部,因此通过mouseover
DIV部分信息将离开屏幕。我想自动控制这种情况,当它的DIV
的任何部分离开屏幕时,滚动条就会下降,直到它到达DIV
的底部
这是我的伪代码,但我无法在jquery中实现它
屏幕高度
divHeight
屏幕高度
<分割高度
+与TopofScreen的分割距离
)则
scroll down to bottom of `DIV`
如果你认为这个算法是正确的,我怎么能实现这样的事情呢?这应该可以做到
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
参考文献:
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
- jQuery偏移量:
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
参考文献:
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
- jQuery偏移量:
Fiddle:在这里发布之前,请实现您的代码并确保其工作正常!除此之外,
DIV
的顶部必须是相对于屏幕的,而不是相对于文档的。显然,您是新来的。一句忠告。这里的人正试图帮助你。如果有人以一种你不一定觉得有用的方式帮助你,而不是对他们大喊大叫,你可以从“谢谢,但是……”开始。这样你会在这里结交更多的朋友。:-)的确,我很感谢你的回复,我只是给了你一个建议,让你在将来发布更多有用的帖子,我的朋友;)请实现您的代码,并确保它在这里张贴之前工作!除此之外,DIV
的顶部必须是相对于屏幕的,而不是相对于文档的。显然,您是新来的。一句忠告。这里的人正试图帮助你。如果有人以一种你不一定觉得有用的方式帮助你,而不是对他们大喊大叫,你可以从“谢谢,但是……”开始。这样你会在这里结交更多的朋友。:-)的确,我很感谢你的回复,我只是给了你一个建议,让你在将来发布更多有用的帖子,我的朋友;)