怎么我的图片特效没出来??救命~~
怎么我的图片特效没出来??救命~~
怎么我的图片特效没出来??救命~~
2016-11-14
<script> window.onload = function () { /*注意添加window.onload*/ var box = document.getElementById("container"); /*获取图片集*/ var imgs = box.getElementsByTagName("img"); /*获取单张图片的宽度*/ var picwidth = imgs[0].offsetWidth; /*定义需要遮盖的宽度*/ var pushwidth = 160; /*整个盒子的总宽度*/ var boxwidth = picwidth + (imgs.length - 1 ) * pushwidth; box.style.width = boxwidth + 'px'; /*定义后面几张图片的左坐标*/ function setimagepos() { for (var i = 1, len = imgs.length; i < len; i++) { imgs[i].style.left = picwidth + (i - 1) * pushwidth + "px"; } }; setimagepos(); /*图片展开需要向左移动的距离*/ var translate = picwidth - pushwidth; for(var i = 0,len = imgs.length;i<len;i++){ (function (i) { imgs[i].onmouseover = function () { setimagepos(); for( var j = 1;j<=i;j++) { imgs[j].style.left = parseInt(imgs[j].style.left,10) - translate +"px"; } } })(i); } } </script> </html>
给你看看我的
举报