Fade In e Fade Out usando JavaScript

Julho 3, 2008

As funções abaixo fazem o objeto sumir ou aparecer, respectivamente:

function fadeOut(id, time) {
        target = $(id);
        alpha = 100;
        timer = (time*1000)/50;
        var i = setInterval(
                        function() {
                                if (alpha <= 0)
                                        clearInterval(i);
                                setAlpha(target, alpha);
                                alpha -= 2;
                        }, timer);
}
function fadeIn(id, time) {
        target = $(id);
        alpha = 0;
        timer = (time*1000)/50;
        var i = setInterval(
                        function() {
                                if (alpha >= 100)
                                        clearInterval(i);
                                setAlpha(target, alpha);
                                alpha += 2;
                        }, timer);
}

Número de meses entre duas datas

Julho 3, 2008

A função abaixo retorna o número de meses que existem entre duas datas:

// Formato das datas deve ser dd/mm/aaaa
// a $data2 deve ser MAIOR que a $data1
function diffMonths($data1, $data2) {
	$d1 = explode("/", $data1);
	$d2 = explode("/", $data2);

	$result = ($d2[2] - $d1[2])*12;
	if ($d1[1] > $d2[1]) {
		$result -= ($d1[1] - $d2[1]);
	} elseif ($d2[1] > $d1[1]) {
		$result += ($d2[1] - $d1[1]);
	}
	return $result;
} // diffMonths