Merge pull request #220 from snide/fix-safari-overscroll

Fix Safari over-scroll bug, fixes #218
This commit is contained in:
Eric Holscher 2015-07-20 11:22:33 -07:00
commit f1208215d7

View File

@ -49,29 +49,30 @@ window.SphinxRtdTheme = (function (jquery) {
var navBar,
win,
winScroll = false,
winResize = false,
linkScroll = false,
winPosition = 0,
winHeight,
docHeight,
enable = function () {
init();
reset();
win.on('hashchange', reset);
// Set scrolling
// Set scroll monitor
win.on('scroll', function () {
if (!linkScroll) {
winScroll = true;
}
});
setInterval(function () {
if (winScroll) {
winScroll = false;
var newWinPosition = win.scrollTop(),
navPosition = navBar.scrollTop(),
newNavPosition = navPosition + (newWinPosition - winPosition);
navBar.scrollTop(newNavPosition);
winPosition = newWinPosition;
}
}, 25);
setInterval(function () { if (winScroll) scroll(); }, 25);
// Set resize monitor
win.on('resize', function () {
winResize = true;
});
setInterval(function () { if (winResize) resize(); }, 25);
resize();
},
init = function () {
navBar = jquery('nav.wy-nav-side:first');
@ -95,6 +96,23 @@ window.SphinxRtdTheme = (function (jquery) {
}
}
},
scroll = function () {
winScroll = false;
var newWinPosition = win.scrollTop(),
winBottom = newWinPosition + winHeight,
navPosition = navBar.scrollTop(),
newNavPosition = navPosition + (newWinPosition - winPosition);
if (newWinPosition < 0 || winBottom > docHeight) {
return;
}
navBar.scrollTop(newNavPosition);
winPosition = newWinPosition;
},
resize = function () {
winResize = false;
winHeight = win.height();
docHeight = $(document).height();
},
hashChange = function () {
linkScroll = true;
win.one('hashchange', function () {