Home:ALL Converter>stick div to screen if bottom of div and screen matches

stick div to screen if bottom of div and screen matches

Ask Time:2014-07-14T12:12:46         Author:user3779574

Json Formatter

Hello all I am working on a project where in a page I have to stick the div to screen (disable scrolling) when its bottom is at the bottom of screen. I have two divs in the page and both the divs are of variable height. I want to stick the div2 and scroll the div1.

<script>
  var divheight
  var scrolltop
  var screenheight
  if(divheight-scrolltop <= screenheight){ 
  /* now stick the div wherever it is i can not 
  use fixed position as both the divs are floating and
   fixing the position will make it to change the position*/ } 
   else { /*un stick the div*/ }
 </script>

i dont know what to put in if and else please help me

Author:user3779574,eproduced under the CC 4.0 BY-SA copyright license with a link to the original source and this disclaimer.
Link to original article:https://stackoverflow.com/questions/24729422/stick-div-to-screen-if-bottom-of-div-and-screen-matches
yy