Foros del Web » Programando para Internet » Javascript »

Girar imagen sobre su eje

Estas en el tema de Girar imagen sobre su eje en el foro de Javascript en Foros del Web. Tengo una idea pero no tengo idea de como hacerlo La cuestión es que quiero girar una imagen sobre su propio eje. Osea, tomo el ...
  #1 (permalink)  
Antiguo 05/11/2011, 15:02
 
Fecha de Ingreso: abril-2010
Ubicación: Ping: BSAS - Arg
Mensajes: 791
Antigüedad: 14 años
Puntos: 25
Girar imagen sobre su eje

Tengo una idea pero no tengo idea de como hacerlo

La cuestión es que quiero girar una imagen sobre su propio eje.
Osea, tomo el borde de la imagen y lo giro hasta cierta posición y luego suelto el clíc y queda allí estático en la nueva posición.

¿Es posible hacer algo así en javascript?
  #2 (permalink)  
Antiguo 06/11/2011, 03:25
Avatar de Panino5001
Me alejo de Omelas
 
Fecha de Ingreso: mayo-2004
Ubicación: -34.637167,-58.462984
Mensajes: 5.148
Antigüedad: 20 años
Puntos: 834
Respuesta: Girar imagen sobre su eje

Fijate si te sirve algo así:
Código PHP:
<!DOCTYPE html>
<
html>
<
head>
<
meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<
title></title>
<
style type="text/css">
#cont{ position:absolute; left:50%; top:50%; margin-top:-175px; margin-left:-250px; cursor:pointer; width:500px; height:350px;}
#cont img{ position:relative}
</style>
<
script type="text/javascript">
function 
rotate(angle){
    var 
rotation Math.PI angle 180;
    var 
costheta Math.cos(rotation);
    var 
sintheta Math.sin(rotation); 
    if(!
window.ActiveXObject){
        
this.style.position='absolute';
        
this.style.webkitTransform ='rotate('+angle+'deg)';
        
this.style.khtmlTransform ='rotate('+angle+'deg)';  
        
this.style.MozTransform='rotate('+angle+'deg)';    
        
this.style.OTransform='rotate('+angle+'deg)';
        
this.style.transform='rotate('+angle+'deg)';
    }else{
        
this.style.filter="progid:DXImageTransform.Microsoft.Matrix(sizingMethod='auto expand')";
        
this.filters.item(0).M11 costheta;
        
this.filters.item(0).M12 = -sintheta;
        
this.filters.item(0).M21 sintheta;
        
this.filters.item(0).M22 costheta
        
this.style.top= ((this.parentNode.offsetHeight/2)-(this.offsetHeight/2))+'px';
        
this.style.left=  ((this.parentNode.offsetWidth/2)-(this.offsetWidth/2))+'px';
    }
}
var 
ns={}
onload=function(){
    (function(){
    
document.getElementById('im').onmousedown=function(){
        var 
_this=this;
        
ns.angulo=ns.angulo || 0;
        
ns.timmer=setInterval(function(){rotate.call(_this,ns.angulo+=5)},30);
    }
    
document.getElementById('im').onmouseup=function(){
        
clearInterval(ns.timmer);
    }
    })();
}
</script>

</head>

<body>
<div id="cont"><img id="im" src="http://www.disegnocentell.com.ar/arwen.jpg" width="500" height="350"  /></div>
</body>
</html> 
Podés verlo funcionando: http://jsfiddle.net/panino/gR9TW/
  #3 (permalink)  
Antiguo 06/11/2011, 07:19
 
Fecha de Ingreso: abril-2010
Ubicación: Ping: BSAS - Arg
Mensajes: 791
Antigüedad: 14 años
Puntos: 25
Respuesta: Girar imagen sobre su eje

Super, era masomenos lo que estaba buscando, ya tengo con que trabajar.
GRACIAS
  #4 (permalink)  
Antiguo 06/11/2011, 07:32
 
Fecha de Ingreso: abril-2010
Ubicación: Ping: BSAS - Arg
Mensajes: 791
Antigüedad: 14 años
Puntos: 25
Respuesta: Girar imagen sobre su eje

Hay un pequeño bug:

Cuando quito el ratón sobre la imagen y sigo haciendo clíc, sigue girando sola la imagen.
Que funcion podria agregar para que deje de girar?
  #5 (permalink)  
Antiguo 06/11/2011, 07:37
 
Fecha de Ingreso: abril-2010
Ubicación: Ping: BSAS - Arg
Mensajes: 791
Antigüedad: 14 años
Puntos: 25
Respuesta: Girar imagen sobre su eje

<div id="cont"><img id="im" src="http://www.disegnocentell.com.ar/arwen.jpg" width="500" height="350" onMouseOut="javascript:clearInterval(ns.timmer);" /></div>

Solucionado!

Etiquetas: girar
Atención: Estás leyendo un tema que no tiene actividad desde hace más de 6 MESES, te recomendamos abrir un Nuevo tema en lugar de responder al actual.
Respuesta




La zona horaria es GMT -6. Ahora son las 01:33.