Never been to DZone Snippets before?

Snippets is a public source code repository. Easily build up your personal collection of code snippets, categorize them with tags / keywords, and share them with the world

« Newer Snippets
Older Snippets »
Showing 21-22 of 22 total

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


<span style="color:red;" help="aaaaaaaaaaa :)<br /><br /><b>uuuuuuuuuu :(</b>">OIIIIIIIIIIII, PASSA A MÃOZINHA EM MIM XD</span>
<span style="color:green;" help="nooossa !!!!<br /><br /><b>affffffff iiii</b>">LALAAAAAAAAAAAAAAAA</span>

<script type="text/javascript">
//<![CDATA[

new ToolTip( "tooltip", "help", true );

//]]>
</script>

Drag and Drop image with javascript

<body>
<script src="http://www.walterzorn.com/scripts/wz_dragdrop.js"></script>

<img name="name1" src="someImg.jpg" width=240 height=135>

<script>SET_DHTML("name1")</script>
</body>

You can make the image resizable (using shift-drag) by
SET_DHTML("name1"+RESIZABLE) // any size
SET_DHTML("name1"+SCALABLE) // keep aspect ratio

See more detail here
http://www.walterzorn.com/dragdrop/dragdrop_e.htm
« Newer Snippets
Older Snippets »
Showing 21-22 of 22 total