Over a million developers have joined DZone.

ToolTip //JavaScript Class

·


[UPDATED CODE AND HELP CAN BE FOUND HERE]


@REQUIRES Event-Listener


//Requires http://www.jsfromhell.com/Geral/event-listener

//+ Jonas Raoni Soares Silva
//@ http://jsfromhell.com/dhtml/tooltip [v1.0]

ToolTip = function( toolTipClass, attributeName, followMouse ){
	var i, o = this;
	o.s = ( o.t = document.body.appendChild( document.createElement( "div" ) ) ).style;
	( o.s.display = "none", o.s.position = "absolute", o.t.className = toolTipClass, o.a = attributeName, o.f = followMouse );
	for( i in { mouseout: 0, mouseover: 0, mousemove: 0 } )
		addEventListener( document, i, function( e ){ o[e.type].call( o, e ); } );
};
with( { p: ToolTip.prototype } ){
	p.mouseout = function(){
		this.s.display = "none";
	};
	p.mouseover = function( e ){
		for( var d = document, x = e.target; !x.getAttribute( this.a ) && ( x = x.parentNode ) != d; );
		if( x == d )
			return;
		( this.s.display = "block", this.s.top = e.clientY + "px", this.s.left = e.clientX + "px", e.stopPropagation() );
		this.t.innerHTML = x.getAttribute( this.a );
	};
	p.mousemove = function( e ){
		if( !this.f )
			return;
		this.s.top = e.clientY + "px";
		this.s.left = e.clientX + "px";
	};
}



Example



OIIIIIIIIIIII, PASSA A MÃOZINHA EM MIM XD
LALAAAAAAAAAAAAAAAA


Topics:

The best of DZone straight to your inbox.

SEE AN EXAMPLE
Please provide a valid email address.

Thanks for subscribing!

Awesome! Check your inbox to verify your email so you can start receiving the latest in tech news and resources.
Subscribe

{{ parent.title || parent.header.title}}

{{ parent.tldr }}

{{ parent.urlSource.name }}