Ver Mensaje Individual
  #1 (permalink)  
Antiguo 03/01/2012, 09:29
marx-pola
 
Fecha de Ingreso: mayo-2002
Ubicación: Capital Federal
Mensajes: 630
Antigüedad: 22 años, 8 meses
Puntos: 1
Tooltip tarda en desaparecer con Jquery

Hola a todos! Tengo un problema con este código que utilizo para mostrar info en unas tooltips. El tema es que al pasar rápido el mouse, las tooltips aparecen y a veces no desaparecen, se quedan congeladas y la idea es que al hacer un onmouseout automaticamente desaparezcan.

Les muestro un pequeño ejemplo ACA - Tooltips. Pasen rápido el mouse por arriba y van a ver que algunas no desaparecen.

Este es el código que utilizo:

Código:
var ajaxtooltip={
	fadeeffect: [true, 150], //enable Fade? [true/false, duration_milliseconds]
	useroffset: [10, 10], //additional x and y offset of tooltip from mouse cursor, respectively
	loadingHTML: '<div style="text-align:center;"></div>',

	positiontip:function($tooltip, e){
		var docwidth=(window.innerWidth)? window.innerWidth-35 : ajaxtooltip.iebody.clientWidth-35
		var docheight=(window.innerHeight)? window.innerHeight-38 : ajaxtooltip.iebody.clientHeight-35
		var twidth=$tooltip.get(0).offsetWidth
		var theight=$tooltip.get(0).offsetHeight
		var tipx=e.pageX+this.useroffset[0]
		var tipy=e.pageY+this.useroffset[1]
		tipx=(e.clientX+twidth>docwidth)? tipx-twidth-(2*this.useroffset[0]) : tipx //account for right edge
		tipy=(e.clientY+theight>docheight)? tipy-theight-(2*this.useroffset[0]) : tipy //account for bottom edge
		$tooltip.css({left: tipx, top: tipy})
	},

	showtip:function($tooltip, e){
		if (this.fadeeffect[0])
			$tooltip.hide().fadeIn(this.fadeeffect[1])
		else
			$tooltip.show()
	},

	hidetip:function($tooltip, e){
		if (this.fadeeffect[0])
			$tooltip.fadeOut(this.fadeeffect[1])
		else
			$tooltip.hide()
	}

}

jQuery(document).ready(function(){
	ajaxtooltip.iebody=(document.compatMode && document.compatMode!="BackCompat")? document.documentElement : document.body
	var tooltips=[] //array to contain references to all tooltip DIVs on the page
	$('*[@title^="ajax:"]').each(function(index){ //find all links with "title=ajax:" declaration
		this.titleurl=jQuery.trim(this.getAttribute('title').split(':')[1]) //get URL of external file
		this.titleposition=index+' pos' //remember this tooltip DIV's position relative to its peers
		tooltips.push($('<div class="ajaxtooltip"></div>').appendTo('body'))
		var $target=$(this)
		$target.removeAttr('title','<div class="ajaxtooltip"></div>')
		$target.hover(
			function(e){ //onMouseover element
				var $tooltip=tooltips[parseInt(this.titleposition)]
				if (!$tooltip.get(0).loadsuccess){ //first time fetching Ajax content for this tooltip?
					$tooltip.html(ajaxtooltip.loadingHTML).show()
					$tooltip.load(this.titleurl, '', function(){
						ajaxtooltip.positiontip($tooltip, e)
						ajaxtooltip.showtip($tooltip, e)
						$tooltip.get(0).loadsuccess=true
					})

				}
				else{
					ajaxtooltip.positiontip($tooltip, e)
					ajaxtooltip.showtip($tooltip, e)
				}
			},
			function(e){ //onMouseout element
				var $tooltip=tooltips[parseInt(this.titleposition)]
				ajaxtooltip.hidetip($tooltip, e)		
			}
		)
		$target.bind("mousemove", function(e){
			var $tooltip=tooltips[parseInt(this.titleposition)]
			ajaxtooltip.positiontip($tooltip, e)
		})
	})
})
Y lo llamo desde acá:

index.php
Código:
<script type="text/javascript" src="jquery-1.2.2.pack.js"></script>

<style type="text/css">

.ajaxtooltip{
position: absolute; /*leave this alone*/
display: none; /*leave this alone*/
width: 300px;
left: 0; /*leave this alone*/
top: 0; /*leave this alone*/
background: lightyellow;
border: 2px solid gray;
border-width: 1px 2px 2px 1px;
padding: 5px;
}

</style>

<script type="text/javascript" src="ajaxtooltip.js"></script>

..........

// y muestro el tooltip al pasar por arriba de esta manera

<div id="cont-foto" title="ajax:tooltip.php?id_producto='.$registro['id_producto'].'"><a href="rpauto-detalle.php?id_producto='.$registro['id_producto'].'" target="_top"><img src="'.$filename.'" border="0" /></a></div>
Como les decia antes, todo funciona pero muchas veces los tooltips no desaparecen.

¿Me podrían decir por favor que se peude hacer para que SIEMPRE desaparezcan?

Muchas gracias y saludos.
Marx
__________________
"Todo lo que somos es el resultado de lo que hemos pensado". Budda.