js实现图片自动切换效果

var moves;
        $(function() {
            var imgs = $("#imgs li");
            //取的里标签的个数
            var currentIndex = imgs.length;

            moves = function () {
                var img = $(sh(getCurrentIndex()));
                //alert(currentIndex);
                //$(sh(currentIndex-1<0?imgs.length-1:currentIndex-1)).css({zIndex:-1});
                img.animate({left: "-=100%"}, 1000, function () {
                    img.css({left: 0, zIndex: -2});
                    window.setTimeout("moves()", 3000);
                });
            };
            moves();
            //返回img的位置3,2,1
            function getCurrentIndex() {
                if (currentIndex < 1) {
                    currentIndex = imgs.length;
                }
                return --currentIndex;
            }

            function sh(index) {
                //imgs是定义取的数据
                $.each(imgs, function (i, img) {
                    if (i != index) {
                    document.title = i+"="+index;
                        $(img).css({
                            "z-index": -2
                        });
                    }
                });
                $(imgs[index - 1 < 0 ? imgs.length - 1 : index - 1]).css({
                    "z-index": -1
                })
                return $(imgs[index]).css({
                    "z-index": -0
                });
            }
            });
    </script>
    <style>
        *{margin:0px; padding:0px;}
        a{text-decoration:none;}
        ul{list-style:none;}
        img{ border:0;}
        #neck{position:relative; text-align:center;background:#efefef;z-index:-1;height:750px; }
        #imgs li{position:absolute;top:0px; left:0px;width:100%;}

    </style>
</head>
<body>
<div id="neck">
    <ul id="imgs">
        <li><a href="#"><img src="bootstrap/1.jpg" /></a></li>
        <li><a href="#"><img src="bootstrap/2.jpg" /></a></li>
        <li><a href="#"><img src="bootstrap/3.jpg"/></a></li>
    </ul>
    <div style="clear:both;"></div>
</div>

</div>
</body>
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值