我想这样做,当你点击链接滚动顺利上移。但不知何故setTimeout不起作用。下面的代码:平滑滚动不起作用
window.onscroll = function(e) {
var a = document.getElementsByTagName('a')[0];
a.style.opacity = (window.pageYOffset > document.documentElement.clientHeight) ? 1 : 0;
}
document.getElementsByTagName('a')[0].onclick = top;
function top() {
if(window.pageYOffset != 0){
window.scrollBy(0, -10);
setTimeout(top, 100);
}
}
链接到沙箱:http://jsfiddle.net/b7by1so8/
谢谢!然后尝试了解自己。 – Aleksandr