vue relateds
Created
August 20, 2016 13:42
-
-
Save bushuai/36db796d411a76d6d468becb9770bac4 to your computer and use it in GitHub Desktop.
Q: Failed to mount component: template or render function not defined. (found in root instance) #713
A: vuejs/vue-router#713
/**
@description 页面垂直平滑滚动到指定滚动高度
@author zhangxinxu(.com)
*/
var scrollSmoothTo = function (position) {
if (!window.requestAnimationFrame) {
window.requestAnimationFrame = function(callback, element) {
return setTimeout(callback, 17);
};
}
// 当前滚动高度
var scrollTop = document.documentElement.scrollTop || document.body.scrollTop;
// 滚动step方法
var step = function () {
// 距离目标滚动距离
var distance = position - scrollTop;
// 目标滚动位置
scrollTop = scrollTop + distance / 5;
if (Math.abs(distance) < 1) {
window.scrollTo(0, position);
} else {
window.scrollTo(0, scrollTop);
requestAnimationFrame(step);
}
};
step();
};
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
https://codepen.io/awp/pen/NGamRR