title、alt的提示效果

字號:


    在網(wǎng)頁中,有時我們將鼠標移到圖片上,或者文字鏈接處,會出現(xiàn)文字型的提示信息。一般制作這樣的效果極為簡單,只需在圖片代碼中加入<alt=文字提示信息>或者在文字鏈接代碼中加入<title=文字提示信息>。仔細觀察一下,感覺出現(xiàn)的信息總有時間上的停頓。如何制作類似于網(wǎng)頁教學網(wǎng)首頁文字超鏈接的提示信息的效果呢?
    制作方法一:加入js代碼
    1、在頁面的<head></head>中加入js代碼:
    <script language=javascript>
    var tiptimer;
    function locateobject(n, d) { //v3.0
    var p,i,x; if(!d) d=document; if((p=n.indexof(?))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
    if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
    for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=locateobject(n,d.layers[i].document); return x;
    }
    function hidetooltip(object)
    {
    if (document.all)
    {
    locateobject(object).style.visibility=hidden
    locateobject(object).style.left = 1;
    locateobject(object).style.top = 1;
    return false
    }
    else if (document.layers)
    {
    locateobject(object).visibility=hide
    locateobject(object).left = 1;
    locateobject(object).top = 1;
    return false
    }
    else
    return true
    }
    function showtooltip(object,e, tipcontent, backcolor, bordercolor, textcolor, displaytime)
    {
    window.cleartimeout(tiptimer)
    if (document.all)
    {
    locateobject(object).style.top=document.body.scrolltop+event.clienty+20
    locateobject(object).innerhtml='<table style=font-family: verdana,tahoma, arial, helvetica, sans-serif; font-size: 11px; border: '+bordercolor+'; border-style: solid; border-top-width: 1px; border-right-width: 1px; border-bottom-width: 1px; border-left-width: 1px; background-color: '+backcolor+' width=10 border=0 cellspacing=1 cellpadding=1><tr><td nowrap><font style=font-family: verdana,tahoma, arial, helvetica, sans-serif; font-size: 11px; color: '+textcolor+'>'+unescape(tipcontent)+'</font></td></tr></table> '
    if ((e.x + locateobject(object).clientwidth) > (document.body.clientwidth + document.body.scrollleft))
    {
    locateobject(object).style.left = (document.body.clientwidth + document.body.scrollleft) - locateobject(object).clientwidth-10;
    }
    else
    {
    locateobject(object).style.left=document.body.scrollleft+event.clientx
    }
    locateobject(object).style.visibility=visible
    tiptimer=window.settimeout(hidetooltip('+object+'), displaytime);
    return true;
    }
    else if (document.layers)
    {
    locateobject(object).document.write('<table width=10 border=0 cellspacing=1 cellpadding=1><tr bgcolor='+bordercolor+'><td><table width=10 border=0 cellspacing=0 cellpadding=2><tr bgcolor='+backcolor+'><td nowrap><font style=font-family: verdana,tahoma, arial, helvetica, sans-serif; font-size: 11px; color: '+textcolor+'>'+unescape(tipcontent)+'</font></td></tr></table></td></tr></table>')
    locateobject(object).document.close()
    locateobject(object).top=e.y+20
    if ((e.x + locateobject(object).clip.width) > (window.pagexoffset + window.innerwidth))
    {
    locateobject(object).left = window.innerwidth - locateobject(object).clip.width-10;
    }
    else
    {
    locateobject(object).left=e.x;
    }
    locateobject(object).visibility=show
    tiptimer=window.settimeout(hidetooltip('+object+'), displaytime);
    return true;
    }
    else
    {
    return true;
    }
    }
    </script>
    注意紅色字體部分,可以對出現(xiàn)的提示信息進行字體的格式化與提示框的控制,不包括對文字顏色的修改。
    2、在<body></body>中插入代碼:
    <div id=dhtmltooltip style=position: absolute; visibility: hidden; width:10; height: 10; z-index: 1000; left: 0; top: 0></div>
    3、在文字超鏈接處加入代碼:
    onmouseover=showtooltip('dhtmltooltip',event, '文字提示信息部分', '#fffff2','#000000','#000000','20000') onmouseout=hidetooltip('dhtmltooltip')
    紅色字體部分為你需加注的提示信息內(nèi)容;
    注意加粗部分:
    #fffff2為彈出信息框的背景色;
    #000000為彈出信息框的邊框顏色;
    #000000為提示信息的文字顏色;
    20000為控制的顯示時間。