-
Notifications
You must be signed in to change notification settings - Fork 32
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
1,096 additions
and
45 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Large diffs are not rendered by default.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
import TWEEN from '@tweenjs/tween.js' | ||
|
||
const requestAnimationFrame = (function () { | ||
return window.requestAnimationFrame || | ||
window.webkitRequestAnimationFrame || | ||
window.mozRequestAnimationFrame || | ||
window.oRequestAnimationFrame || | ||
window.msRequestAnimationFrame || | ||
function (callback) { | ||
window.setTimeout(callback, 1000 / 60) | ||
} | ||
})() | ||
|
||
function animate () { | ||
if (TWEEN.update()) { | ||
requestAnimationFrame(animate) | ||
} | ||
} | ||
|
||
requestAnimationFrame(animate) | ||
|
||
export const Easing = TWEEN.Easing | ||
|
||
export function scrollWithAnimation (scrollEl, current, target, time, easing) { | ||
new TWEEN.Tween({ postion: current }) | ||
.to({ postion: target }, time) | ||
.easing(easing) | ||
.onUpdate(function (val) { | ||
scrollEl.scrollTop = val.postion | ||
}) | ||
.start() | ||
|
||
animate() | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters