Just a little piece of code I condensed as much as possible to produce simple tooltips, with fading transitions.

Javascript:

// Flash Chilli Animated Tooltips
var tooltip=function(){
	var id = 'tt';
	var top = 10;
	var left = 15;
	var maxw = 300;
	var speed = 10;
	var timer = 20;
	var endalpha = 95;
	var alpha = 0;
	var tt,t,c,b,h;
	var ie = document.all ? true : false;
	return{
		show:function(v,w){
			if(tt == null){
				tt = document.createElement('div');
				tt.setAttribute('id',id);
				document.body.appendChild(tt);
				tt.style.opacity = 0;
				tt.style.filter = 'alpha(opacity=0)';
				document.onmousemove = this.pos;
			}
			tt.style.display = 'block';
			tt.innerHTML = v;
			tt.style.width = w ? w + 'px' : 'auto';
			if(!w && ie){
				tt.style.width = tt.offsetWidth;
			}
			if(tt.offsetWidth > maxw){tt.style.width = maxw + 'px'}
			h = parseInt(tt.offsetHeight) + top;
			clearInterval(tt.timer);
			tt.timer = setInterval(function(){tooltip.fade(1)},timer);
		},
		pos:function(e){
			var u = ie ? event.clientY + document.documentElement.scrollTop : e.pageY;
			var l = ie ? event.clientX + document.documentElement.scrollLeft : e.pageX;
			tt.style.top = (u + top) + 'px';
			tt.style.left = (l + left) + 'px';
		},
		fade:function(d){
			var a = alpha;
			if((a != endalpha && d == 1) || (a != 0 && d == -1)){
				var i = speed;
				if(endalpha - a < speed && d == 1){
					i = endalpha - a;
				}else if(alpha < speed && d == -1){
					i = a;
				}
				alpha = a + (i * d);
				tt.style.opacity = alpha * .01;
				tt.style.filter = 'alpha(opacity=' + alpha + ')';
			}else{
				clearInterval(tt.timer);
				if(d == -1){tt.style.display = 'none'}
			}
		},
		hide:function(){
			clearInterval(tt.timer);
			tt.timer = setInterval(function(){tooltip.fade(-1)},timer);
		}
	};
}();

CSS:

#tt {
	position: absolute;
	display: block;
	padding: 3px 10px 5px 10px;
	background: #666;
	border: 1px solid #333;;
	color: #fff;
}

Usage example:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>JavaScript Tooltip Demo</title>
<link rel="stylesheet" type="text/css" href="style.css" />
<style type="text/css" media="all">
* {
	margin:0; padding:0
}
body {
	font:11px/1.5 Verdana, Arial, Helvetica, sans-serif; background:#FFF
}
#text {
	margin:50px auto; width:500px
}
.hotspot {
	color:#900; padding-bottom:1px; border-bottom:1px dotted #900; cursor:pointer
}
</style>
</head>
<body>
<p id="text">Lorem ipsum dolor sit amet, <span class="hotspot" onmouseover="tooltip.show('Testing 123 <strong>Testing 123</strong>');" onmouseout="tooltip.hide();">consectetuer adipiscing</span> elit. Aliquam id tellus. Nulla orci enim, vulputate et, pharetra eget, imperdiet non, sem. Mauris sit amet mi nec nulla porttitor dapibus. Curabitur leo sem, lacinia sed, commodo eu, mattis sit amet, felis. Ut tortor. Donec <span class="hotspot" onmouseover="tooltip.show('Testing 123<br />Testing 123');" onmouseout="tooltip.hide();">porttitor orci</span> et neque. Curabitur eget diam at libero egestas suscipit. In tortor est, ullamcorper eu, dapibus et, condimentum nec, nunc. Pellentesque habitant morbi tristique senectus et netus et malesuada fames ac turpis egestas. Duis vel <span class="hotspot" onmouseover="tooltip.show('<img src=\'images/x_icon.gif\'/>');" onmouseout="tooltip.hide();">purus eget diam</span> aliquam luctus. Nullam risus ipsum, aliquam et, lacinia sit amet, fermentum vel, mi. In hac habitasse platea dictumst. Maecenas et dui non tortor lobortis feugiat. Donec eleifend iaculis arcu. Cras vitae leo nec nunc rhoncus laoreet. Integer eget enim. Nunc <span class="hotspot" onmouseover="tooltip.show('<strong>Lorem ipsum dolor sit amet</strong><br />Consectetuer adipiscing elit. Praesent lacinia, dui ut consequat bibendum, lorem dolor tristique tellus, at faucibus nibh est in orci. In pede.');" onmouseout="tooltip.hide();">dignissim cursus</span> mi. Donec eros.</p>
<script type="text/javascript" language="javascript" src="script.js"></script>
</body>
</html>

NOTICE: This code doesn’t support multiple actions at once, and doesn’t operate as expected when the div makes use of css padding and borders. I am working hard to update my code but in the meantime please use Harry Maugan’s Animated DIV With Javascript. Thank you.

This is a little javascript code to collapse/expand a div without any running frameworks (jQuery, ect.)

// Flash Chilli Content slider - Copyright 2009 Flash Chilli
var FCTIMER = 15;
var FCBUSY = false;

function fcExpand(id, speed) {
if(!FCBUSY) {
var el = document.getElementById(id);
el.style.overflow = 'hidden';
var temph = el.offsetHeight;
el.style.height = 'auto';
if(temph !== el.offsetHeight) {
el.orgh = el.offsetHeight;
el.style.height = temph;
}
FCBUSY = true;
el.timer = setInterval(function(){fcSlide(el, 1, speed)}, FCTIMER);
}
}

function fcCollapse(id, speed) {
if(!FCBUSY) {
var el = document.getElementById(id);
el.style.overflow = 'hidden';
var temph = el.offsetHeight;
el.style.height = 'auto';
if(temph !== el.offsetHeight) {
el.orgh = el.offsetHeight;
el.style.height = temph;
}
FCBUSY = true;
el.timer = setInterval(function(){fcSlide(el, 0, speed)}, FCTIMER);
}
}

function fcToggle(id, speed) {
if(document.getElementById(id).offsetHeight > 0) {
fcCollapse(id, speed);
} else {
fcExpand(id, speed);
}
}

function fcSlide(el, direction, speed) {
var curh = el.offsetHeight;
if(direction == 0) { speed = 0 - speed; }

if(direction == 0 && (curh + speed) < 1) {
el.style.height = '0px';
clearInterval(el.timer);
FCBUSY = false;
} else if(direction == 1 && (curh + speed) > (el.orgh - 1)) {
el.style.height = el.orgh + 'px';
clearInterval(el.timer);
FCBUSY = false;
} else {
el.style.height = curh + speed + 'px';
}
}

Usage example:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Slider test</title>
<script type="text/javascript" src="slider.js"></script>
</head>
<body>
<a href="#" onclick="fcCollapse('mydiv', 2);">Collapse It!</a> <a href="#" onclick="fcExpand('mydiv', 2);">Expand It!</a>
<a href="#" onclick="fcToggle('mydiv', 5);">Toggle It!</a>
<a href="#" onclick="alert(document.getElementById('mydiv').offsetHeight);">Check Height</a><br  /><br />

<div id="mydiv" style="background-color:#cc9">
Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Nam ultricies libero a urna. Curabitur eget arcu. Proin fringilla congue diam. Mauris mollis, risus id porttitor pharetra, felis quam pulvinar neque, sit amet pellentesque justo risus quis lectus. Aliquam accumsan. Duis iaculis quam a mi. Pellentesque nulla nunc, molestie sed, commodo sed, ultrices et, lectus. Donec hendrerit sollicitudin ipsum. Vestibulum ante ipsum primis in faucibus orci luctus et ultrices posuere cubilia Curae; Phasellus nec felis. Donec turpis felis, dignissim eu, lacinia vel, cursus in, nibh. Phasellus id orci. Aliquam augue. Morbi posuere mollis libero. Sed lobortis sagittis urna.
</div>
</body>
</html>

MiniAJAX (http://www.miniajax.com) lists tonnes of free AJAX scripts that you can download freely. Check it out!

This great tutorial by .NET Butchering shows you how to combine PHP and AJAX to create a chat system that can asynchronously send and recieve messages:
http://dotnetbutchering.blogspot.com/2008/02/php-ajax-mysql-simple-ajax-chat-in-php.html

Looking to get started with AJAX (Asynchronos Javascript and XML)?
http://www.mousewhisperer.co.uk/ajax_page.html

You can also find lots more help and free AJAX projects here:
http://www.ajaxprojects.com/

Want a web WYSIWYG that’s free, easy to use, customizable and poweful?

Take a look at TinyMCE (http://tinymce.moxiecode.com). This is a great package that will turn any textarea into a fully featured WYSIWYG editor! Whats more there are loads of plugins and skins available on the website and forums, plus it’s simple to make your own with the help of their doucumentation.

TinyMCE runs through javascript but you can extend it’s functionallity by providing it with a server-side language like PHP or ASP. Also includes AJAX support to dynamically save pages!

So what are you waiting for? http://tinymce.moxiecode.com.


© 2007 Flash Chilli | Flash Chilli Wordpress Theme | Powered by Wordpress