Finestrella tooltip che compare al passaggio del mouse su un link
Grazie a questo javascript verrà visualizzata unafinestrella descrittiva accanto al link su cui passa ilmouse.
Per inserire lo script, dobbiamo mettere questo codiceall'interno del tag head:
<STYLE> /* This is for Netscape 4.0+ broswsers so that the border will display. If you want to modify the background color this is where you would do it for NS4.0+. To modify the color for IE and NS6 do so in the style tag in the div below */ .ttip {border:1px solid black;font-size:12px;layer-background-color:lightyellow;background-color:lightyellow} </STYLE><script>//Script created by Jim Young (www.requestcode.com)//Submitted to JavaScript Kit (http://javascriptkit.com)//Visit http://javascriptkit.com for this script//Set the tool tip message you want for each link here. var tip=new Array tip[0]='Visit Dynamic Drive<br> for DHTML Scripts!' tip[1]='Visit JavaScript Kit for Great<br> Scripts, Tutorials and Forums!' tip[2]='Visit Request Code for FREE JavaScripts!' tip[3]='Click here for some excellent<br>Java applets and tutorials' function showtip(current,e,num) { if (document.layers) // Netscape 4.0+{ theString="<DIV CLASS='ttip'>" +tip[num]+ "</DIV>" document.tooltip.document.write(theString) document.tooltip.document.close() document.tooltip.left=e.pageX+14 document.tooltip.top=e.pageY+2 document.tooltip.visibility="show"} else {if(document.getElementById) // Netscape 6.0+ and Internet Explorer 5.0+ { elm=document.getElementById("tooltip") elml=current elm.innerHTML=tip[num] elm.style.height=elml.style.height elm.style.top=parseInt(elml.offsetTop+elml.offsetHeight) elm.style.left=parseInt(elml.offsetLeft+elml.offsetWidth+10) elm.style.visibility = "visible" } } }function hidetip(){if (document.layers) // Netscape 4.0+ { document.tooltip.visibility="hidden" }else { if(document.getElementById) // Netscape 6.0+ and Internet Explorer 5.0+ {elm.style.visibility="hidden" } } }</script> Adesso basterà solamente inserire questo codiceall'interno del tag body:
<div id="tooltip" style="position:absolute;visibility:hidden;border:1px solid black;font-size:12px;layer-background-color:lightyellow;background-color:lightyellow;padding:1px"></div><a href="http://www.dynamicdrive.com" onMouseover="showtip(this,event,'0')" onMouseOut="hidetip()">Dynamic Drive</a><br><a href="http://www.javascriptkit.com" onMouseover="showtip(this,event,'1')" onMouseOut="hidetip()">JavaScript Kit</a><br><a href="http://www.requestcode.com" onMouseover="showtip(this,event,'2')" onMouseOut="hidetip()">Request Code</a><br><a href="http://www.htmlgoodies.com" onMouseover="showtip(this,event,'3')" onMouseOut="hidetip()">Freewarejava</a>
Per ogni link è presente un codice all'interno deltag head, come questo:
tip[0]='Visit Dynamic Drive<br> for DHTML Scripts!'
e un codice all'interno del tag body, come questo:
<a href="http://www.dynamicdrive.com" onMouseover="showtip(this,event,'0')" onMouseOut="hidetip()">Dynamic Drive</a>
Analizziamo la parte in grassetto evidenziate nel primocodice, quello relativo al tag head:
Visit Dynamic Drive<br> for DHTML Scripts! =E' la frase che comparirà nella finestra (inquesto caso è stato anche inserito un tag<br> per andare a capo, in modo da non renderela finestrella troppo lunga)
Mentre nel secondo, quello riferito al tag body:
http://www.dynamicdrive.com = L'url del link
Dynamic Drive = Il testo relativo al link
Basterà modificare queste poche righe per utilizzarelo script.
Per problemi relativi all'utilizzo di questojavascript, potete consultare il nostroforum.
- Articolo precedente Visualizzare un calendario e un orologio
- Articolo successivo Inserire un sottofondo musicale in una pagina
