Tuesday, March 3, 2015

[JQuery] Get height of multiple divs with jquery

http://stackoverflow.com/questions/14782087/get-height-of-multiple-divs-with-jquery

<div id="parent" style="position: relative;">
      <div id="leftMenu">Here is left menu</div>
      <div id="rightMenu">Here is right menu</div>
</div>

$("[id$='parent']").bind('scroll', function() {
       var scrollerHeight = $("[id$='parent']").outerHeight(true);
      var scrollVal = $("[id$='parent']").scrollTop();
      var top = 0;
       if ( scrollVal > (scrollerHeight - 50)) {
        top = scrollVal - (scrollerHeight - 50);
           $('#rightMenu').css({'position':'absolute','right':'2em','top' :top+'px'});
       } else {
           $('#rightMenu').css({'position':'static','top':'0px'});
       }
});

No comments:

Post a Comment