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, var navBar,
win, win,
winScroll = false, winScroll = false,
winResize = false,
linkScroll = false, linkScroll = false,
winPosition = 0, winPosition = 0,
winHeight,
docHeight,
enable = function () { enable = function () {
init(); init();
reset(); reset();
win.on('hashchange', reset); win.on('hashchange', reset);
// Set scrolling // Set scroll monitor
win.on('scroll', function () { win.on('scroll', function () {
if (!linkScroll) { if (!linkScroll) {
winScroll = true; winScroll = true;
} }
}); });
setInterval(function () { setInterval(function () { if (winScroll) scroll(); }, 25);
if (winScroll) {
winScroll = false; // Set resize monitor
var newWinPosition = win.scrollTop(), win.on('resize', function () {
navPosition = navBar.scrollTop(), winResize = true;
newNavPosition = navPosition + (newWinPosition - winPosition); });
navBar.scrollTop(newNavPosition); setInterval(function () { if (winResize) resize(); }, 25);
winPosition = newWinPosition; resize();
}
}, 25);
}, },
init = function () { init = function () {
navBar = jquery('nav.wy-nav-side:first'); 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 () { hashChange = function () {
linkScroll = true; linkScroll = true;
win.one('hashchange', function () { win.one('hashchange', function () {