Skip to content

Commit

Permalink
调整导航显示逻辑,通过鼠标位置预判区域
Browse files Browse the repository at this point in the history
  • Loading branch information
bh-lay committed Nov 11, 2017
1 parent a8c13ef commit df3b97b
Showing 1 changed file with 8 additions and 5 deletions.
13 changes: 8 additions & 5 deletions frontEnd/single-page/src/js/navigation.js
Original file line number Diff line number Diff line change
Expand Up @@ -50,27 +50,30 @@ function init () {
let isDarkened = false;
let darkenClassName = 'darken';
let useMethod;
let lastScrollTop = 0;
let scrollTop = 0;
let mouseY = 1000;

function fixNavClass () {
let scrollTop = getScrollTop();
let isNeedDarken = scrollTop > distance;
// let isNeedDarken = lastScrollTop > scrollTop && scrollTop > distance;
let isNeedDarken = mouseY < 200 || scrollTop > distance;
let isNeedChange = isNeedDarken !== isDarkened;
if (isNeedChange) {
isDarkened = isNeedDarken;
useMethod = (isNeedDarken ? 'add' : 'remove') + 'Class';

utils[useMethod](nodeNav, darkenClassName);
}
lastScrollTop = scrollTop;
}

window.onscroll = function () {
scrollTop = getScrollTop();
fixNavClass();
clearTimeout(scrollDelay);
scrollDelay = setTimeout(checkBackTop, 100);
};
window.onmousemove = function (e) {
mouseY = e.clientY;
fixNavClass();
};
utils.bind(nodeBackTop, 'click', function () {
nodeBody.scrollTop = 0;
});
Expand Down

0 comments on commit df3b97b

Please sign in to comment.