Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixed bug: #4480 scrolling up jumpy behaviour #4539

Open
wants to merge 1 commit into
base: dev
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
74 changes: 17 additions & 57 deletions src/js/beyondFullpage/beyondFullPageHandler.js
Original file line number Diff line number Diff line change
@@ -1,75 +1,35 @@
import * as utils from '../common/utils.js';
import { getState, setState } from "../common/state.js";
import { getState } from "../common/state.js";
import { setPrevTime } from '../common/tick.js';
import { wheelDataHandler } from './wheelDataHandler.js';
import { getScrollSettings } from '../common/utilsFP.js';
import { scrollUpToFullpage } from './scrollBeyondFullPage.js';

export function beyondFullPageHandler(container, e){
var curTime = new Date().getTime();
var pauseScroll = getState().isBeyondFullpage && container.getBoundingClientRect().bottom >= 0 && wheelDataHandler.getDirection() === 'up';
var g_isAboutToScrollToFullPage = getState().isAboutToScrollToFullPage;
// Register the event and get current mousewheel scrolling direction
wheelDataHandler.registerEvent(e);
var scrollWheelDirection = wheelDataHandler.getDirection();

if(g_isAboutToScrollToFullPage){
if (g_isAboutToScrollToFullPage) {
setPrevTime(curTime);
utils.preventDefault(e);
return false;
}

if(getState().isBeyondFullpage){
if(!pauseScroll){
keyframeTime('set', 'beyondFullpage', 1000);
if (getState().isBeyondFullpage) {
// If user is beyound the fullpage, let's check fullpage container position.
// The scrolling direction we already got by "getDirection".
var containerBounding = container.getBoundingClientRect();
if (containerBounding.bottom >= 0 && scrollWheelDirection === 'up') {
// move to the fullpage container only if user scrolls up and fullpage container is in the viewport
scrollUpToFullpage();
utils.preventDefault(e);
return false;
}
else {
var shouldSetFixedPosition = !g_isAboutToScrollToFullPage && (!keyframeTime('isNewKeyframe', 'beyondFullpage') || !wheelDataHandler.isAccelerating() );
var scrollSettings;
if( shouldSetFixedPosition ){
scrollSettings = getScrollSettings(utils.getLast(getState().sections).item.offsetTop + utils.getLast(getState().sections).item.offsetHeight);
scrollSettings.element.scrollTo(0, scrollSettings.options);
setState({isAboutToScrollToFullPage: false});

utils.preventDefault(e);
return false;
}
else if( wheelDataHandler.isAccelerating() ){
pauseScroll = false;
setState({isAboutToScrollToFullPage: true});
setState({scrollTrigger: 'wheel'});

scrollUpToFullpage();

utils.preventDefault(e);
return false;
}
}

if(!g_isAboutToScrollToFullPage){

if (!g_isAboutToScrollToFullPage) {
// allow normal scrolling, but quitting
if(!pauseScroll){
return true;
}
return true;
}
}
}

var keyframeTime = (function(){
let isNew = false;
var frames = {};
var timeframes = {};

return function(action, name, timeframe){
switch(action){
case 'set':
frames[name] = new Date().getTime();
timeframes[name] = timeframe;
break;
case 'isNewKeyframe':
const current = new Date().getTime();
isNew = current - frames[name] > timeframes[name];
break;
}

return isNew;
};
})();
}