要求:滚动鼠标时,触发滚动事件;
问题:滚动时,没有触发事件;
html,body{
overflow-x: hidden;
font-size: 16px;
color: #666;
margin: 0 auto;
width: 100%;
height: 100%;
}
window.onscroll = function () {
console.log('我执行了')
}
错误原因:我在写样式时对,body和html设置了 width: 100%; height: 100%;,这样绑定在 window上的滚动事件是无法触发的。
参考:https://blog.csdn.net/starandsea/article/details/42773707