<!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 >
    <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>

 

相关文章:

  • 2022-02-07
  • 2022-02-07
  • 2022-02-17
  • 2021-11-24
  • 2022-12-23
  • 2021-06-10
  • 2021-11-17
  • 2022-12-23
猜你喜欢
  • 2022-12-23
  • 2021-04-17
  • 2022-12-23
  • 2021-12-05
  • 2022-12-23
  • 2022-02-07
相关资源
相似解决方案