雪花+切换背景图片

这里我加入的是通过鼠标点击事件来实现切换图片效果,以白皑皑的雪花为点缀,实现一种简单的视觉效果。

<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>L O V E</title>
    <link rel="shortcut icon" href="favicon.ico" type="images/x-icon" />
    <style>
        * {
            margin: 0;
            padding: 0;
        }

        body {
            background-image: url("img/6-.jpg");
        }

        #mask {
            background-color: rgba(255, 255, 255, 0.3);
            height: 200px;
            text-align: center;
        }

        #mask img {
            width: 200px;
            margin-top: 35px;
            cursor: pointer;
        }

        .snow-container {
            position: absolute;
            height: 100%;
            width: 100%;
            max-width: 100%;
            top: 0;
            overflow: hidden;
            z-index: 2;
            pointer-events: none;
            /*background-color: red;*/
        }

        .snow {
            display: block;
            position: absolute;
            z-index: 2;
            top: 0;
            right: 0;
            bottom: 0;
            left: 0;
            pointer-events: none;
            -webkit-transform: translate3d(0, -100%, 0);
            transform: translate3d(0, -100%, 0);
            -webkit-animation: snow linear infinite;
            animation: snow linear infinite;
        }
        .snow.foreground {
            background-image: url("img/snow1.png");
            -webkit-animation-duration: 15s;
            animation-duration: 15s;
        }
        .snow.foreground.layered {
            -webkit-animation-delay: 7.5s;
            animation-delay: 7.5s;
        }
        .snow.middleground {
            background-image: url("img/snow2.png");
            -webkit-animation-duration: 20s;
            animation-duration: 20s;
        }
        .snow.middleground.layered {
            -webkit-animation-delay: 10s;
            animation-delay: 10s;
        }
        .snow.background {
            background-image: url(https://dl6rt3mwcjzxg.cloudfront.net/assets/snow/snow-small-1ecd03b1fce08c24e064ff8c0a72c519.png);
            -webkit-animation-duration: 30s;
            animation-duration: 30s;
        }
        .snow.background.layered {
            -webkit-animation-delay: 15s;
            animation-delay: 15s;
        }

        @-webkit-keyframes snow {
            0% {
                -webkit-transform: translate3d(0, -100%, 0);
                transform: translate3d(0, -100%, 0);
            }
            100% {
                -webkit-transform: translate3d(15%, 100%, 0);
                transform: translate3d(15%, 100%, 0);
            }
        }
        @keyframes snow {
            0% {
                -webkit-transform: translate3d(0, -100%, 0);
                transform: translate3d(0, -100%, 0);
            }
            100% {
                -webkit-transform: translate3d(15%, 100%, 0);
                transform: translate3d(15%, 100%, 0);
            }
        }

    </style>

</head>
<body id="bd">
<audio autoplay controls loop>  //音频插入
    <source src="Angel.mp3"/>
</audio>
<div id="mask">
    <img src="img/6-.jpg" alt="">
    <img src="img/7.jpg" alt="">
    <img src="img/11.jpg" alt="">
    <img src="img/5.jpg" alt="">
    <img src="img/6.jpg" alt="">
</div>
<div class="snow-container">
    <div class="snow foreground"></div>
    <div class="snow foreground layered"></div>
    <div class="snow middleground"></div>
    <div class="snow middleground layered"></div>
    <div class="snow background"></div>
    <div class="snow background layered"></div>
</div>


<script src="common.js"></script>
<script>
    var imgObjs=my$("mask").children;//获取的所有的子元素
    //循环遍历所有img,注册点击事件
    for(var i=0;i<imgObjs.length;i++){
        imgObjs[i].onclick=function () {
            document.body.style.backgroundImage="url("+this.src+")";
        };
    }
</script>

</body>
</html>

有不足之处还请大家多多指点。

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值