2017-01-14更新(修复火狐翻浏览器转后,还是同一张图片问题,感谢heroes7提供的方法)
在页面中引入jquery和样式文件style.css。
1 2 | < script src = "path/to/jquery.min.js" ></ script > < link href = "path/to/style.css" rel = "stylesheet" > |
该品牌图片使用一个无序列表作为HTML结构:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 | < ul id = "iconWall" > < li > < div class = "img-3d" > < div class = "img-back" > < img src = "img/icon1.jpg" alt = "" > </ div > < div class = "img-front" > < img src = "img/icon11.jpg" alt = "" > </ div > </ div > < div class = "mask" > < img src = "img/heart.png" alt = "" > < p >关注人数 323.4万</ p > < a href = "javascript:" >点击进入</ a > </ div > </ li > < li > < div class = "img-3d" > < div class = "img-back" > < img src = "img/icon2.jpg" alt = "" > </ div > < div class = "img-front" > < img src = "img/icon12.jpg" alt = "" > </ div > </ div > < div class = "mask" > < img src = "img/heart.png" alt = "" > < p >关注人数 323.4万</ p > < a href = "javascript:" >点击进入</ a > </ div > </ li > ...... < li id = "btnRefresh" > < div class = "iconRefresh" ></ div > < span >换一批</ span > </ li > </ ul > |
在页面DOM元素加载完毕之后,通过下面的js代码来完成按钮的点击事件,以及品牌图片的翻转动画。
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 | window.onload = function () { var clickTimes = 1; //总列数 var lineCount = 6; var btnRefresh = document.querySelector( "#btnRefresh" ); var iconRefresh = document.querySelector( ".iconRefresh" ) var img3DList = document.querySelectorAll( ".img-3d" ); var len = img3DList.length; btnRefresh.onclick = function () { iconRefresh.style.transition = ".3s linear" ; iconRefresh.style.transform = "rotate(" + 360 * clickTimes + "deg)" ; for ( var i = 0; i < len; i++) { var colNum = parseInt(i / lineCount); var rowNum = i % lineCount; var delayTime = (colNum + rowNum) * 100; img3DList[i].style.transition = ".3s " + delayTime + "ms linear" ; img3DList[i].style.transform = "rotateY(" + 180 * clickTimes + "deg)" ; } clickTimes++; } } |
特别申明:
本站所有资源都是由网友投稿发布,或转载各大下载站,请自行检测软件的完整性!
本站所有资源仅供学习与参考,请勿用于商业用途,否则产生的一切后果将由您自己承担!
如有侵权请联系我们删除下架,联系方式:lei1294551502@163.com