没懂哪里不对。。。http://www.imooc.com/video/3173
<!DOCTYPE html> <html> <head> <meta charset="utf-8"> <title></title> <style type="text/css"> * { margin: 0; padding: 0; } #move { width: 300px; height: 170px; margin: 10px auto; border: 1px solid #ccc; } #move a { display: inline-block; width: 58px; height: 55px; border: 1px solid #ddd; border-radius: 3px; background-color: #fff; text-align: center; margin: 10px 17px; position: relative; color: #9c9c9c; font-size: 12px; text-decoration: none; line-height: 25px; overflow: hidden; opacity: 1; filter: Alpha(opacity=100); } #move a i { position: absolute; top: 20px; left: 0; display: inline-block; width: 100%; text-align: center; } #move img { padding: 3px 0; border: none; z-index:-1 } #move a:hover { color: #f00; } </style> window.onload=function(){ var as=document.getElementById("move").getElementsByTagName("a"); for(var i=0;i<as.length;i++){ as[i].onmouseover=function(){ var ai=this.getElementsByTagName('i')[0]; lis_over(ai,{top:-25,opacity:0},function(){ ai.style.top=30+'px'; lis_over(ai,{top:20,opacity:1}) }); } } } </script> </head> <body> <div id="move"> <a href="#"> <i><img src="images/food.png"></i> <p>淘宝</p> </a> <a href="#"> <i><img src="images/game.png"></i> <p>天猫</p> </a> <a href="#"> <i><img src="images/insurance.png"></i> <p>京东</p> </a> <a href="#"> <i><img src="images/lottery.png"></i> <p>易迅</p> </a> <a href="#"> <i><img src="images/movie.png"></i> <p>国美</p> </a> <a href="#"> <i><img src="images/travel.png"></i> <p>苏宁</p> </a> </div> </body> </html>
function lis_over(obj, json, fn) { obj.timer = null; clearInterval(obj.timer); obj.timer = setInterval(function() { var flag = true; for (var sty in json) { //样式值处理 var wd = window.getComputedStyle(obj, null)[sty]; if (sty == 'opacity') { wd = Math.round(parseFloat(wd) * 100) / 100; } else { wd = parseInt(wd); } var speed =(json[sty] - wd) / 6; speed = speed > 0 ? Math.ceil(speed) : Math.floor(speed); //console.log('sty:'+sty+';wd:'+wd+';sty:'+json[sty]); if(wd!=json[sty]){ flag=false; } //透明度 if (sty == 'opacity') { var a = wd * 100 + speed; obj.style[sty] = a / 100; } else { //其他 obj.style[sty] = wd + speed + "px"; } if (flag) { clearInterval(obj.timer); if (fn) { fn(); } } } }, 50) }
啥子情况?感谢啊。。。