请教大佬window.onload和window.onscroll冲突问题

js里同时存在window.onload和window.onscroll,结果不能执行window.onscroll事件,请问怎么解决,谢谢!代码如下
window.onload = function () {
//旋转的圆
rotate();
var circleIn = document.getElementById("circle1");
var circleOut = document.getElementById("circle2");
circleOut.onmouseover = circleIn.onmouseover = function () {
circleOut.style.fill = "red";
}
function rotate() {
circletimer = setInterval(function () {
var circleIn = document.getElementById("circle1");
var circleOut = document.getElementById("circle2");
rotateVal += 1;
circleIn.style.transform = 'rotate(' + rotateVal + 'deg)';
circleIn.style.transition = '0.1s linear';
}, 50)
}
}
window.scroll = function () {
var Header = document.getElementById("NavigationBar");
var scrolltop = document.documentElement.scrollTop || document.body.scrollTop;
if (scrolltop <= 100) {
startMove(Header, { top: -200, opacity: 0 });
}
else {
startMove(Header, { top: 0, opacity: 100 });
}
}

2个回答

  window.onload = function() {
        console.log('页面重新加载啦');
    }

    window.addEventListener('scroll', function() {
        console.log('页面滚动啦')
    });

不是冲突,是你onscroll没写 on
window.onscroll = function () {

Csdn user default icon
上传中...
上传图片
插入图片
抄袭、复制答案,以达到刷声望分或其他目的的行为,在CSDN问答是严格禁止的,一经发现立刻封号。是时候展现真正的技术了!
立即提问
相关内容推荐