Difference between revisions of "Team:Uppsala/test5"

Line 363: Line 363:
 
         </div>
 
         </div>
 
     </div>
 
     </div>
 +
<script>
  
 +
var stickySidebar = $('.toctext');
 +
 +
if (stickySidebar.length > 0) {
 +
  var stickyHeight = stickySidebar.height(),
 +
      sidebarTop = stickySidebar.offset().top;
 +
}
 +
 +
// on scroll move the sidebar
 +
$(window).scroll(function () {
 +
  if (stickySidebar.length > 0) {
 +
    var scrollTop = $(window).scrollTop();
 +
           
 +
    if (sidebarTop < scrollTop) {
 +
      stickySidebar.css('top', scrollTop - sidebarTop);
 +
 +
      // stop the sticky sidebar at the footer to avoid overlapping
 +
      var sidebarBottom = stickySidebar.offset().top + stickyHeight,
 +
          stickyStop = $('.main-content').offset().top + $('.main-content').height();
 +
      if (stickyStop < sidebarBottom) {
 +
        var stopPosition = $('.main-content').height() - stickyHeight;
 +
        stickySidebar.css('top', stopPosition);
 +
      }
 +
    }
 +
    else {
 +
      stickySidebar.css('top', '0');
 +
    }
 +
  }
 +
});
 +
 +
$(window).resize(function () {
 +
  if (stickySidebar.length > 0) {
 +
    stickyHeight = stickySidebar.height();
 +
  }
 +
});
 +
 +
</script>
 
</html>
 
</html>

Revision as of 20:14, 15 October 2018




Uppsala iGEM 2018