参考了百度空间的做法,关键点是不使用display而是visibility来控制是否显示,这样就没有了事件源转移而导致的闪动问题。
<div class="cell"> <div class='c_opera' style="visibility:hidden;"><a href="#">删除</a></div> <div class="c_title">个人图片</div> <div style="position:static;" class='c_logo'><img class='imgStyle' src="http://misc.home.news.cn/blog/images/random_small.jpg" border=0/></div> <div class="c_info"><br/>?</div> </div> (function() { function doOnload() { var cell, opera, cellLists = $("mt").getElementsByTagName("div"); for(var i = cellLists.length - 1; i >= 0; i--) { cell = cellLists[i]; if(cell && cell.className == "cell") { opera = getElementsByClassName("c_opera",cell)[0]; opera.id = "c_opera" + i; cell.name = i; cell.onmouseover = cellMOver; cell.onmouseout = cellMOut; } } } function cellMOver(event) { $("c_opera" + this.name).style["visibility"] = "visible"; } function cellMOut(event) { $("c_opera" + this.name).style["visibility"] = "hidden"; } //附加 onload事件 EventUtil.addEventHandler(window, "load", doOnload); })();
?