javascript - how to scroll to set the bottom of a DIV at the bottom of the screen (monitor) -
there div
in website , height not fixed. when user moves mouse on image div
appeared , display information image. there several images in grid format on page , every 1 has own information. images @ bottom of screen mouseover
section of information div
off screen. want automatically control situation , when section of div
off screen scrollbar goes down until reaches bottom of div
.
this pseudo code not implement in jquery.
- calculate
screenheight
- calculate
divheight
- calculate
divdistancefromtopofscreen
if (screenheight
< divheight
+ divdistancefromtopofscreen
) then
scroll down bottom of `div`
if think algorithm right how can implement such thing?
this should it.
javascript:
var top = $('.thediv').offset().top; // top of div relative document var div_height = $('.thediv').height(); // height of div window.scrollto(0, top + div_height); // scroll bottom of div
references:
- jquery offset: http://api.jquery.com/offset/
Comments
Post a Comment