一段JavaScript代码,实现悬停预览功能
作者: Aion 日期: 2006-05-10 09:35
CODE:
<script language="javascript" type="text/javascript">
var sPop = null;
document.write("<style type='text/css'>");
document.write(".PopText { font-family: Tahoma, 宋体; color: #3B676E; background-color: #ffffff; border: 2px #37a1b7 solid; font-size: 14px; font-weight: bold; line-height: 20px; padding: 0px 10px 0px 10px; visibility: hidden; filter: Alpha(Opacity=0)}");
document.write("</style>");
document.write("<div id='popLayer' style='position:absolute;z-index:1000;filter:revealtrans(duration=.5,transition=12) revealTrans(duration=.5,transition=12) alpha(opacity=90,enabled=100)' class='PopText'></div>");
function showPopupText() {
var o=event.srcElement;
MouseX=event.x;
MouseY=event.y;
if(o.alt!=null && o.alt!="") { o.pop=o.alt;o.alt="" }
if(o.title!=null && o.title!=""){ o.pop=o.title;o.title="" }
if(o.pop) {
o.pop=o.pop.replace("
","
");
o.pop=o.pop.replace("
","
");
}
if(o.pop!=sPop) {
sPop=o.pop;
if(sPop==null || sPop=="") {
popLayer.filters[0].apply();
popLayer.style.visibility="hidden";
popLayer.filters[0].play();
popLayer.style.width=""
} else {
if(o.dyclass!=null) popStyle=o.dyclass
else popStyle="PopText";
popLayer.filters[1].apply();
popLayer.style.visibility="visible";
popLayer.filters[1].play();
showIt();
if (popLayer.offsetWidth>500)
{
popLayer.style.width=500
}
}
}
}
function showIt() {
popLayer.className=popStyle;
popLayer.innerHTML=sPop;
popWidth=popLayer.clientWidth;
popHeight=popLayer.clientHeight;
if(event.clientX+12+popWidth>document.body.clientWidth) popLeftAdjust=-popWidth-24
else popLeftAdjust=0;
if(event.clientY+12+popHeight>document.body.clientHeight) popTopAdjust=-popHeight-24
else popTopAdjust=0;
popLayer.style.left=event.clientX+12+document.body.scrollLeft+popLeftAdjust;
popLayer.style.top=event.clientY+12+document.body.scrollTop+popTopAdjust;
}
document.onmouseover=showPopupText;
</script>
使用例子:
CODE:
<a title="<div class='words'>PIC NAME: Angel Down
Update: Dec.25.2005</div><img src='http://www.anycc.com/download/angel.down.JPG' class='pic' /><div class='sign'>Anycc.com</div>" href="#">把鼠标移动到这里可以看到效果</a>
评论: 19 |
引用: 3 |
阅读: 2092
发表评论
订阅
上一篇
返回
下一篇