码迷,mamicode.com
首页 > Web开发 > 详细

js+css让背景图片动起来

时间:2017-11-09 19:45:20      阅读:290      评论:0      收藏:0      [点我收藏+]

标签:char   style   rip   script   div   animate   3.2   var   width   

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>css+js让背景图片动起来</title>
    <style>
        *{
            margin:0;
            padding:0;
        }
        #section{
            width: 800px;
            height: 300px;
            margin:0 auto;
            background:url("images/timg_11.jpg");
            background-position-x: 0px;
            background-position-y: 0px;
            background-repeat: repeat;
            background-size:400px 300px;
        }
        .cover{
            width: 100%;
            height: 100%;
            background:rgba(0,0,0,0.5);
            position: relative;
        }
        .cover>h1{
            color: #fff;
            position:absolute;
            top:183.5px;
            left:314.5px;
        }
    </style>
</head>
<body>

<section id="section">
    <div class="cover">
        <h1>WELL IS DONE</h1>
    </div>
</section>
<script src="js/jquery-3.2.1.min.js"></script>
<script>
    var section = $(‘#section‘);
    var x =0;
    function polling() {
        x += 5;
        section.animate({
            ‘background-position-x‘: x+‘%‘,
        }, 400, ‘linear‘);
        setTimeout(polling,300)
    }

    polling();
</script>

</body>
</html>

 

js+css让背景图片动起来

标签:char   style   rip   script   div   animate   3.2   var   width   

原文地址:http://www.cnblogs.com/yingleiming/p/7810772.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!