页面滚动视觉效果实现

<body style="background-repeat: no-repeat;margin: 0 auto; height: 5000px;">         
<div style="width:100%;position:relative;height: 800px;background-color: #ff5684;">
<h1>感谢观看</h1>
<h1>感谢观看</h1>
<h1>感谢观看</h1>
<h1>感谢观看</h1>
<h1>感谢观看</h1>
</div>
<div style="width:100%;position:relative;height: 800px;background-color: #B2DBA1;margin-top: 700px;">
<h1>感谢观看</h1>
<h1>感谢观看</h1>
<h1>感谢观看</h1>
<h1>感谢观看</h1>
<h1>感谢观看</h1>
</div>
<div style="width:100%;position:relative;height: 800px;background-color: skyblue;margin-top: 700px;">
<h1>感谢观看</h1>
<h1>感谢观看</h1>
<h1>感谢观看</h1>
<h1>感谢观看</h1>
<h1>感谢观看</h1>
</div>

</body>



<script type="text/javascript">
//检查浏览器 是否支持
    function scroll() {
        //判断当前的浏览器是否是IE9+ 或者其他浏览器
        if (window.pageYOffset != null) {
            return {
                left: window.pageXOffset,
                top: window.pageYOffset
            };
        }
        //检测是否是怪异模式浏览器,就是没有声明<!DOCTYPE html>
        else if(document.compatMode == "CSS1Compat"){
            //正常模式
            return {
                left: document.documentElement.scrollLeft,
                top: document.documentElement.scrollTop
            };
        }
        //怪异浏览器
        return {
            left:document.body.scrollLeft,
            top:document.body.scrollTop
        };
    }




//核心滚动代码
    window.onscroll = function () {
    //backgroundAttachment 属性设置背景图像是否固定或者随着页面的其余部分滚动。
        var dis = scroll().top;
        if(dis <= 1500){
            document.body.style.backgroundImage = "url(img/IMG_3441.JPG)";
            document.body.style.backgroundAttachment = "fixed";


            
        }
        else if(dis > 1500&& dis<3000){
            document.body.style.backgroundImage = "url(img/IMG_3443.JPG)";
            document.body.style.backgroundAttachment = "fixed";
        }else{
            document.body.style.backgroundImage = "url(img/IMG_3442.JPG)";
            document.body.style.backgroundAttachment = "fixed";
        }
    }
</script>


  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值