晨风牧笛 2019-05-31 09:45 采纳率: 100%
浏览 675

前端jquery 图片自动轮播

我想要实现图片的自动轮播,并且可以点击图片在新页面查看图片,刚开始的一次循环点击图片可以跳转新页面,可是之后的点击却无效

<!doctype

<html>
<head>
<meta charset="UTF-8">
<title>Demo13-2</title>
<style>
    .container{width:300px;height:150px;margin:200px auto;}
    .left,.right{width:10%;height:100%;line-height:150px;text-align: center;float:left}
    .picbox{width:80%;height:100%;float:left;overflow: hidden;}
    .pic{position:relative;width:720px;overflow:visible}
    img{width:100%;height:100%}
    .img{width:240px;height:150px;float:left}
</style>
<script src="js/jquery-3.3.1.js"></script>
<script>
    $(function(){
        var stop =false;
        var index = -1;
        var pics = ["1","2","3"];
        $.each(pics,function(index,value){
            $(".pic").append($("<div class='img'><a href='img/"+value+".jpg'><image src='img/"+value+".jpg' /></a></div>"));
        })
        $(".pic").hover(function(){stop=true;},function(){stop=false;});
        setInterval(function(){
            if(stop) return;
            var left = parseInt($(".pic").css("left"))-1;
            //alert(left);
            $(".pic").css({left:left});
            if(left % 240 ==0)
            {
                index++;
                var w = parseInt($(".pic").css("width")) +240 ;
                $(".pic").css({"width":w})
                $(".pic").append($("<div class='img'><image src='img/"+pics[index%pics.length]+".jpg' /></div>"));
            }
        },10);

    })
</script>
</head>

<body>
    <div class="container">
        <div class="left"></div>
        <div class="picbox">
            <div class="pic"></div>
        </div>
        <div class="right"></div>
    </div>
</body>
</html>


  • 写回答

1条回答 默认 最新

  • 张兴华(MarsXH.Chang) 前端领域新星创作者 2019-05-31 11:18
    关注
    <html>
    <head>
    <meta charset="UTF-8">
    <title>Demo13-2</title>
    <style>
        .container{width:300px;height:150px;margin:200px auto;}
        .left,.right{width:10%;height:100%;line-height:150px;text-align: center;float:left}
        .picbox{width:80%;height:100%;float:left;overflow: hidden;}
        .pic{position:relative;width:720px;overflow:visible}
        img{width:100%;height:100%}
        .img{width:240px;height:150px;float:left}
    </style>
    <script src="https://code.jquery.com/jquery-3.1.1.min.js"></script>
    <script>
        $(function(){
            var stop =false;
            var index = -1;
            var pics = ["1","2","3"];
            $.each(pics,function(index,value){
                $(".pic").append($("<div class='img'><a href='img/"+value+".jpg'><image src='img/"+value+".jpg' /></a></div>"));
            })
            $(".pic").hover(function(){stop=true;},function(){stop=false;});
            setInterval(function(){
                if(stop) return;
                var left = parseInt($(".pic").css("left"))-1;
                //alert(left);
                $(".pic").css({left:left});
                if(left % 240 ==0)
                {
                    index++;
                    var w = parseInt($(".pic").css("width")) +240 ;
                    $(".pic").css({"width":w})
                    $(".pic").append($("<div class='img'><a href='img/"+pics[index%pics.length]+".jpg'><image src='img/"+pics[index%pics.length]+".jpg' /></a></div>"));
                }
            },10);
    
        })
    </script>
    </head>
    
    <body>
        <div class="container">
            <div class="left"></div>
            <div class="picbox">
                <div class="pic"></div>
            </div>
            <div class="right"></div>
        </div>
    </body>
    </html>
    
    
    
    评论

报告相同问题?

悬赏问题

  • ¥30 这是哪个作者做的宝宝起名网站
  • ¥60 版本过低apk如何修改可以兼容新的安卓系统
  • ¥25 由IPR导致的DRIVER_POWER_STATE_FAILURE蓝屏
  • ¥50 有数据,怎么建立模型求影响全要素生产率的因素
  • ¥50 有数据,怎么用matlab求全要素生产率
  • ¥15 TI的insta-spin例程
  • ¥15 完成下列问题完成下列问题
  • ¥15 C#算法问题, 不知道怎么处理这个数据的转换
  • ¥15 YoloV5 第三方库的版本对照问题
  • ¥15 请完成下列相关问题!