forked from halo-battle/game
52 lines
No EOL
1.4 KiB
JavaScript
52 lines
No EOL
1.4 KiB
JavaScript
function create(type,parent,id,classe)
|
|
{
|
|
var element = document.createElement(type);
|
|
if(id && !$(id)) element.setAttribute('id',id);
|
|
if(classe) Element.addClassName(element,classe);
|
|
if(parent) element = $(parent).appendChild(element);
|
|
return element;
|
|
}
|
|
|
|
function callback()
|
|
{
|
|
if(parameters.length == 0) return false;
|
|
funct = prameters.shift();
|
|
if(typeof funct != 'function') return false;
|
|
|
|
return function() { funct.apply(this,parameters); };
|
|
}
|
|
|
|
function move(objet,relative,from,to,speed)
|
|
{
|
|
switch(relative)
|
|
{
|
|
case 'top':
|
|
case 'bottom':
|
|
case 'left':
|
|
case 'right':
|
|
|
|
for(var i=1; i <= (Math.floor(Math.abs(from - to))) ;i++)
|
|
{
|
|
setTimeout(callback(function(i) {$(objet).style[relative] = (from < to ? from + i : from -i)+'px';},i),Math.floor(speed / (Math.floor(Math.abs(from - to))) * i));
|
|
}
|
|
break;
|
|
default: return false;
|
|
}
|
|
|
|
}
|
|
|
|
function fade(objet,from,to,speed)
|
|
{
|
|
for(var i = 1; (Math.floor(Math.abs(from - to)) / 10) >= i; i++)
|
|
{
|
|
setTimeout(callback(function(i) {opacity(objet,(from < to ? from + i * 10 : from - i * 10));},i),Math.floor(speed / (Math.floor(Math.abs(from - to)) / 10)) * i);
|
|
}
|
|
}
|
|
|
|
function opacity(objet,opacity)
|
|
{
|
|
$(objet).style.opacity = opacity / 100;
|
|
$(objet).style.MozOpacity = opacity /100;
|
|
$(objet).style.KhtmlOpacity = opacity / 100;
|
|
$(objet).style.filter = "alpha(opacity="+opacity+")";
|
|
} |