我在JS中有一个带有简单“回到顶部”脚本的按钮,它将用户带到页面顶部。如何使用经典JS为这款机芯添加平滑度?
答案 0 :(得分:0)
当然,这是JS代码:
window.onload = function() {
var scrollUp = document.getElementById('scrollup');
scrollUp.onmouseover = function() {
scrollUp.style.opacity=0.5;
scrollUp.style.filter = 'alpha(opacity=30)';
};
scrollUp.onmouseout = function() {
scrollUp.style.opacity = 0.9;
scrollUp.style.filter = 'alpha(opacity=50)';
};
scrollUp.onclick = function() {
window.scrollTo(0,0);
};
// show button
window.onscroll = function () {
if ( window.pageYOffset > 0 ) {
scrollUp.style.display = 'block';
} else {
scrollUp.style.display = 'none';
}
};
};
该按钮是id =“scrollup”
的元素