首页 > Web开发 > 详细

js实现图片无缝轮播

时间:2019-03-31 16:09:52      阅读:117      评论:0      收藏:0      [点我收藏+]
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>js实现图片无缝轮播</title>
    <script src="https://code.jquery.com/jquery-3.3.1.min.js"></script>
</head>
<style>
    .b2{
        width: 200px;
        height: 200px;
        margin: 44px auto 0;
        position: relative;
        overflow: hidden;
        background-color: gray;
    }
    .b2 .b2list{
        width: 600px;
        height: 200px;
        position: absolute;
        top: 0;
        left: 0;
    }
    .b2 .item{
        width: 200px;
        height: 200px;
        float: left;
    }
    .b2 .item:nth-child(1) {
        background-image: url("https://ximg.2cq.com/img/system/ad/tieba/7665cfeb1b50e560693509b7a4045861.jpeg");
        background-size: 200px 200px;
    }
    .b2 .item:nth-child(2){
        background-image: url("https://ximg.2cq.com/img/system/ad/tieba/ee34f88f37b317849cc0e80076b89bab.jpeg");
        background-size: 200px 200px;
    }
    .b2 .item:nth-child(3){
        background-image: url("https://ximg.2cq.com/img/system/ad/tieba/1c9b819f1b9ede319e8e1b8ba63066e8.jpeg");
        background-size: 200px 200px;
    }
</style>
<body>
    <div class="b2">
        <div class="b2list" data="0">
            <div class="item">1</div>
            <div class="item">2</div>
            <div class="item">3</div>
        </div>
    </div>
    <script>
        $(function(){
            setInterval("auto_left_me();",3000);
        });
        function auto_left_me(){
            var num = $(".b2 .b2list").attr("data");
            num++;

            if(num>2){
                num=0;
            }
            $(".b2 .b2list").attr("data",num);
            $(.b2 .b2list).animate({left:-200*num});
        }

    </script>
</body>
</html>

 

js实现图片无缝轮播

原文:https://www.cnblogs.com/cl94/p/10631655.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!