You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
28 lines
750 B
JavaScript
28 lines
750 B
JavaScript
export default (el, binding) => {
|
|
let total = document.getElementById(binding).offsetTop;
|
|
let distance = document.documentElement.scrollTop || document.body.scrollTop;
|
|
let step = total / 50;
|
|
if (total > distance) {
|
|
(function smoothDown() {
|
|
if (distance < total) {
|
|
distance += step;
|
|
document.documentElement.scrollTop = distance;
|
|
setTimeout(smoothDown, 5);
|
|
} else {
|
|
document.documentElement.scrollTop = total;
|
|
}
|
|
})();
|
|
} else {
|
|
let newTotal = distance - total;
|
|
step = newTotal / 50;
|
|
(function smoothUp() {
|
|
if (distance > total) {
|
|
distance -= step;
|
|
document.documentElement.scrollTop = distance;
|
|
setTimeout(smoothUp, 5);
|
|
} else {
|
|
document.documentElement.scrollTop = total;
|
|
}
|
|
})();
|
|
}
|
|
} |