qq_43651302
CutyDragon
采纳率0%
2019-01-21 10:29

请教大佬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条回答

  • m0_37852904 阡路陌人 2年前
      window.onload = function() {
            console.log('页面重新加载啦');
        }
    
        window.addEventListener('scroll', function() {
            console.log('页面滚动啦')
        });
    
    点赞 1 评论 复制链接分享
  • jslang 天际的海浪 2年前

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

    点赞 评论 复制链接分享

相关推荐