[英]how to scroll to set the bottom of a DIV at the bottom of the screen (monitor)
我的網站上有一個DIV
,它的高度不是固定的。 當用戶在圖像上移動鼠標時,將顯示此DIV
,並將顯示有關該圖像的一些信息。 頁面上有幾張網格格式的圖像,每個圖像都有自己的信息。 顯然,某些圖像位於屏幕底部,因此,通過將mouseover
在其部分信息上, DIV
將不在屏幕上。 我想自動控制這種情況,當它的DIV
任何部分不在屏幕上時,滾動條就會下降,直到到達DIV
的底部。
這是我的偽代碼,但是我無法在jquery中實現它。
screenHeight
divHeight
divDistanceFromTopOfScreen
如果 ( screenHeight
< divHeight
+ divDistanceFromTopOfScreen
) 然后
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
參考文獻:
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.