24 lines
814 B
JavaScript
24 lines
814 B
JavaScript
const xOffsetUpdate = (pstate, nextOffsetXFn) => {
|
|
let nextOffsetX = nextOffsetXFn();
|
|
const { width, xOffset, xScale, time, sidebarWidth } = pstate;
|
|
|
|
const maxOffsetX = width + xScale * time * 1.0; // maximum offset
|
|
nextOffsetX = Math.min(nextOffsetX, maxOffsetX);
|
|
|
|
const minOffsetX = - width - xScale * time * 1.2; // minimum offset
|
|
nextOffsetX = Math.max(nextOffsetX, minOffsetX);
|
|
|
|
// console.log('max offset', maxOffsetX);
|
|
// console.log('min offset', minOffsetX);
|
|
// console.log('next offset', nextOffsetX);
|
|
|
|
if (nextOffsetX === xOffset) {
|
|
return false; // exit without scroll
|
|
}
|
|
|
|
pstate.oldXOffset = pstate.xOffset;
|
|
pstate.xOffset = nextOffsetX;
|
|
return true;
|
|
};
|
|
|
|
export default xOffsetUpdate; |