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.

  1. calculate screenheight
  2. calculate divheight
  3. 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:

fiddle: http://jsfiddle.net/manishie/ngdbl/


Comments

Popular posts from this blog

java.util.scanner - How to read and add only numbers to array from a text file -

rewrite - Trouble with Wordpress multiple custom querystrings -