js实现图片自动切换效果
2016-03-28 15:38
791 查看
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>
相关文章推荐
- Js 函数eval() 用法记录
- 使用 jsPlumb 绘制拓扑图 —— 异步载入与绘制的实现
- autocomplete 插件用法和用js实现autocomplete
- Javascript异步编程的4种方法
- JavaScript之基础-10 JavaScript 正则表达式(概述、定义正则、RegExp对象、用于模式匹配的String方法)
- js如何获取上个月第一天和最后一天
- javascript——textarea自动伸缩问题
- js控制文本字数,并能点击显示和隐藏
- web js浮点数保留n位小数
- JS设置cookie,删除cookie
- js容易犯错的知识点
- JS进阶书籍
- js辅助添加横向滚动条
- js五种设计模式说明与示例
- JS代码放在何处?
- js中的进制转换
- jstack(查看线程)、jmap(查看内存)和jstat(性能分析)命令
- GetJson
- [BZOJ1015][JSOI2008]星球大战starwar
- javascript中获取class