/**
* @param {elName} String
* @param {speed} Number
*/
Up(elName,speed){
// 直接回到顶部
// var scrollTop = document.getElementsByClassName(‘leftBx‘)[0].scrollTop;
// document.getElementsByClassName(‘leftBx‘)[0].scrollTop = 0
// 缓冲
timer = setInterval(function() {
// 再次获取滚动条距顶部高度
var osTop = document.getElementsByClassName(elName)[0].scrollTop;
// 用于设置速度差,产生缓慢效果
var speed = Math.floor(-osTop / 8);
document.getElementsByClassName(elName)[0].scrollTop = osTop = osTop + speed
if (osTop == 0) {
clearInterval(timer)
}
}, speed)
}
js监听滚动条实现回到顶部