Ver Mensaje Individual
  #1 (permalink)  
Antiguo 02/09/2009, 11:08
ZequeZ
 
Fecha de Ingreso: mayo-2008
Ubicación: En la guarida del mal, tratando de conquistar el mundo
Mensajes: 174
Antigüedad: 16 años
Puntos: 2
Pregunta [Me trabé -.-] ¿Como paso un objeto con setInterval? :S

Bueno, estoy intentando hacer una función para mover una div, que al principio se mueva mucho y luego se mueva mas despacio hasta completar una determinada cantidad de píxeles...

Código PHP:
<html>
    <
head>
        <
title>Prueba JS</title>
        <
script language="JavaScript">
            function 
move(objxa)
            {    
                
dist=parseInt(obj.style.left) - x;
                
sumat=sum(a);
                
window.a=a;;
                
window.inter=setInterval("move2("+obj.id+", "+dist+", "+sumat+")"33);
                
            }

            function 
move2(objid,dist,sumat)
            {
                
obj=document.getElementById(objid);

                if(
dist<0)
                    
obj.style.left=parseInt(obj.style.left)+(dist/sumat)*window.a+"px";
                else
                    
obj.style.left=parseInt(obj.style.left)-(dist/sumat)*window.a+"px";
                
                
window.a--;
                if(
a<0)
                    
clearInterval(window.inter);
            }

            function 
sum(num)
            {
                var 
result=0;
                for(
i=1;i<=num;i++) result+=i;
                return 
result;
            }
        
</script>
    </head>

    <body style="margin:0px;padding:0px;">
        <div id="lol" style="width:100px;height:100px;position:absolute;left:10px;background-color:#000;" onMouseOver="move(this, 800, 100)"></div>
    </body>
</html> 
No se porque, me da un Warnning.
El warnning dice lo que dice el título:

"Element refereced by ID/NAME in the global scope. Use W3C standard document.getElementBydId().instead"

Lo marca en la linea donde está el "setInterval"...
Tengo entendido que no se puede pasar un objeto por "setInterval" porque lo convierte a string... En ese caso, como miercoles hago para pasar un objeto?? :S

Última edición por ZequeZ; 02/09/2009 a las 12:12 Razón: Ups