JS Vprašanje za tooltip
2 naročnika
2 naročnika
lp, nisem ravno vešč v JS programiranju zato se obračam na vas... Zanima me kako lahko naredim da bi mi kazalo tooltip toliko časa dokler je kurzor na divu, ko pa gre kurzor z diva ven pa bi se zaprlo... Uporabljam trenutno skripto ki sem jo dobil tukaj:http://www.dynamicdrive.com/dynamicindex5/fixedtooltip.htm
To pa je koda za prikaz:
<a href="http://www.dasdasds.com" onMouseover="fixedtooltip('tesssssssst texttttttttttt.', this, event, '150px')" onMouseout="delayhidetip()">TEST</a>
Malo spremenjena skripta, ki jo uporabljam:
/***********************************************
* Fixed ToolTip script- © Dynamic Drive (www.dynamicdrive.com)
* This notice MUST stay intact for legal use
* Visit http://www.dynamicdrive.com/ for full source code
***********************************************/
var tipwidth='200px' //default tooltip width
var tipbgcolor='#cccccc' //tooltip bgcolor
var disappeardelay=300 //tooltip disappear speed onMouseout (in miliseconds)
var vertical_offset="-45px" //horizontal offset of tooltip from anchor link
var horizontal_offset="-2px" //horizontal offset of tooltip from anchor link
/////No further editting needed
var ie4=document.all
var ns6=document.getElementById&&!document.all
if (ie4||ns6)
document.write('<div id="fixedtipdiv" style="visibility:hidden;width:'+tipwidth+';background-color:'+tipbgcolor+'" ></div>')
function getposOffset(what, offsettype){
var totaloffset=(offsettype=="left")? what.offsetLeft : what.offsetTop;
var parentEl=what.offsetParent;
while (parentEl!=null){
totaloffset=(offsettype=="left")? totaloffset+parentEl.offsetLeft : totaloffset+parentEl.offsetTop;
parentEl=parentEl.offsetParent;
}
return totaloffset;
}
function showhide(obj, e, visible, hidden, tipwidth){
if (ie4||ns6)
dropmenuobj.style.left=dropmenuobj.style.top=-500
if (tipwidth!=""){
dropmenuobj.widthobj=dropmenuobj.style
dropmenuobj.widthobj.width=tipwidth
}
if (e.type=="click" && obj.visibility==hidden || e.type=="mouseover")
obj.visibility=visible
else if (e.type=="click")
obj.visibility=hidden
}
function iecompattest(){
return (document.compatMode && document.compatMode!="BackCompat")? document.documentElement : document.body
}
function clearbrowseredge(obj, whichedge){
var edgeoffset=(whichedge=="rightedge")? parseInt(horizontal_offset)*-1 : parseInt(vertical_offset)*-1
if (whichedge=="rightedge"){
var windowedge=ie4 && !window.opera? iecompattest().scrollLeft+iecompattest().clientWidth-15 : window.pageXOffset+window.innerWidth-15
dropmenuobj.contentmeasure=dropmenuobj.offsetWidth
if (windowedge-dropmenuobj.x < dropmenuobj.contentmeasure)
edgeoffset=dropmenuobj.contentmeasure-obj.offsetWidth
}
else{
var windowedge=ie4 && !window.opera? iecompattest().scrollTop+iecompattest().clientHeight-15 : window.pageYOffset+window.innerHeight-18
dropmenuobj.contentmeasure=dropmenuobj.offsetHeight
if (windowedge-dropmenuobj.y < dropmenuobj.contentmeasure)
edgeoffset=dropmenuobj.contentmeasure+obj.offsetHeight
}
return edgeoffset
}
function fixedtooltip(menucontents, obj, e, tipwidth){
if (window.event) event.cancelBubble=true
else if (e.stopPropagation) e.stopPropagation()
clearhidetip()
dropmenuobj=document.getElementById? document.getElementById("fixedtipdiv") : fixedtipdiv
dropmenuobj.innerHTML=menucontents
if (ie4||ns6){
showhide(dropmenuobj.style, e, "visible", "hidden", tipwidth)
dropmenuobj.x=getposOffset(obj, "left")
dropmenuobj.y=getposOffset(obj, "top")
dropmenuobj.style.left=dropmenuobj.x-clearbrowseredge(obj, "rightedge")+"px"
dropmenuobj.style.top=dropmenuobj.y-clearbrowseredge(obj, "bottomedge")+obj.offsetHeight+"px"
}
}
function hidetip(e){
if (typeof dropmenuobj!="undefined"){
if (ie4||ns6)
dropmenuobj.style.visibility="hidden"
}
}
function delayhidetip(){
if (ie4||ns6)
delayhide=setTimeout("hidetip()",disappeardelay)
}
function clearhidetip(){
if (typeof delayhide!="undefined")
clearTimeout(delayhide)
}
2 odgovora
Ja, ne ve vezat na element oz. tag <a>, pač pa na <div>, a ne ... :-)
<div onMouseOver="blabla" onMouseOut="blabla"></div> -> tisti div, za katerega želiš za efekt.
Jst mislm bl tko da bi lahka meu kurzor na tooltipu k se odpre. in bi biu odprt dokler je kurzor gor... Zdj je tko narjen da je samo ko je na besedi kurzor (nek linked text) da se odpre tooltip pa če hočm naprimr en link u tooltipu kliknt ne morm ker se prej zapre... kako bi lahk naredu da bi ostou odprt dokler je kurzor na tooltipu