Skip to content

Instantly share code, notes, and snippets.

@liunian
Created July 2, 2013 16:23
Show Gist options
  • Save liunian/5910792 to your computer and use it in GitHub Desktop.
Save liunian/5910792 to your computer and use it in GitHub Desktop.
fix top and scroll bottom
// http://msdn.microsoft.com/zh-cn/library/ie/bg124132(v=vs.85).aspx
epx = window.epx || {}, epx.library = window.epx.library || {}, epx.library.tocFixedModule = function(w, d) {
function init() {
epx.topic && epx.topic.isPrintExperience() === !0 || ($leftNav = $("#leftNav"), $toc = $("#tocnav"), $footer = $("#ux-footer"), w && d && $leftNav.length !== 0 && $toc.length !== 0 && $footer.length !== 0) && ($(w).scroll(function() {
setPosition()
}), $(w).resize(function() {
setPosition()
}))
}
function setPosition() {
var tocHeight = $toc.height(), nonFooterViewable;
$(w).height() > tocHeight && $(w).scrollTop() > $leftNav.offset().top ? ($toc.width($leftNav.width()).css("position", "fixed"), $leftNav.css("height", $toc.height()), nonFooterViewable = $(d).height() - $footer.height() - $(w).scrollTop() - 20, nonFooterViewable >= tocHeight ? $toc.css("top", "0") : $toc.css("top", (tocHeight - nonFooterViewable) * -1)) : ($toc.css("width", "").css("position", "").css("top", ""), $leftNav.css("height", "auto"))
}
var $leftNav, $toc, $footer;
return {init: init,setPosition: setPosition}
}, epx.library.tocFixed = epx.library.tocFixedModule(window, document), $(document).ready(function() {
epx.library.tocFixed.init()
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment