winsock 发表于 2006 年 3 月 31 日 17:51:53

自定义ALT效果 (JS)

浏览器默认的alt提示框的是黑字黄框,下面这段代码有助于你美化alt提示框

PS:把下面这段代码加入到页面的 <head>部分即可。。
<script language=javascript>
<!--
//***********默认设置定义.*********************
tPopWait=50;                //停留tWait豪秒后显示提示。
tPopShow=6000;                //显示tShow豪秒后关闭提示
showPopStep=20;
popopacity=95;
fontcolor="#000000"; //alt提示中字体的颜色
bgcolor="#EDEDED";//alt提示框背景色
bordercolor="#999999";

//***************内部变量定义*****************
sPop=null;curShow=null;tFadeout=null;tFadeIn=null;tFadeWaiting=null;

document.write("<style type='text/css'id='defaultPopStyle'>");
document.write(".cPopText {background-color: " + bgcolor + ";color:" + fontcolor + "; border: 1px " + bordercolor + " solid;font-color: font-size: 12px; padding-right: 4px; padding-left: 4px; height: 20px; padding-top: 2px; padding-bottom: 2px; filter: Alpha(opacity=0)}");
document.write("</style>");
document.write("<div id='dypopLayer' style='position:absolute;z-index:1000;' class='cPopText'></div>");


function showPopupText(){
var o=event.srcElement;
        MouseX=event.x;
        MouseY=event.y;
        if(o.alt!=null && o.alt!=""){o.dypop=o.alt;o.alt=""};
      if(o.title!=null && o.title!=""){o.dypop=o.title;o.title=""};
        if(o.dypop!=sPop) {
                        sPop=o.dypop;
                        clearTimeout(curShow);
                        clearTimeout(tFadeout);
                        clearTimeout(tFadeIn);
                        clearTimeout(tFadeWaiting);       
                        if(sPop==null || sPop=="") {
                                dypopLayer.innerHTML="";
                                dypopLayer.style.filter="Alpha()";
                                dypopLayer.filters.Alpha.opacity=0;       
                                }
                        else {
                                if(o.dyclass!=null) popStyle=o.dyclass
                                        else popStyle="cPopText";
                                curShow=setTimeout("showIt()",tPopWait);
                        }
                       
        }
}

function showIt(){
                dypopLayer.className=popStyle;
                dypopLayer.innerHTML=sPop;
                popWidth=dypopLayer.clientWidth;
                popHeight=dypopLayer.clientHeight;
                if(MouseX+12+popWidth>document.body.clientWidth) popLeftAdjust=-popWidth-24
                        else popLeftAdjust=0;
                if(MouseY+12+popHeight>document.body.clientHeight) popTopAdjust=-popHeight-24
                        else popTopAdjust=0;
                dypopLayer.style.left=MouseX+12+document.body.scrollLeft+popLeftAdjust;
                dypopLayer.style.top=MouseY+12+document.body.scrollTop+popTopAdjust;
                dypopLayer.style.filter="Alpha(opacity=0)";
                fadeout();
}

function fadeout(){
        if(dypopLayer.filters.Alpha.opacity<popopacity) {
                dypopLayer.filters.Alpha.opacity+=showPopStep;
                tFadeout=setTimeout("fadeout()",1);
                }
                else {
                        dypopLayer.filters.Alpha.opacity=popopacity;
                        tFadeWaiting=setTimeout("fadeIn()",tPopShow);
                        }
}

function fadeIn(){
        if(dypopLayer.filters.Alpha.opacity>0) {
                dypopLayer.filters.Alpha.opacity-=1;
                tFadeIn=setTimeout("fadeIn()",1);
                }
}
document.onmouseover=showPopupText;
-->
</script>

xchange 发表于 2006 年 4 月 1 日 00:04:42

http://pic.jgwy.net/46.jpg
美女,我要

esnak 发表于 2006 年 4 月 3 日 23:10:41

有一个,这个拿来比对一下

oghuz 发表于 2006 年 4 月 4 日 07:59:37

看看先
页: [1]
查看完整版本: 自定义ALT效果 (JS)