Ver Mensaje Individual
  #4 (permalink)  
Antiguo 24/01/2012, 20:39
MARCASTELEON
 
Fecha de Ingreso: octubre-2010
Mensajes: 107
Antigüedad: 13 años, 6 meses
Puntos: 14
Respuesta: Crear div con mouse click

Prueba con este codigo, lo hize en poco tiempo pero talvez te sirva de base para hacer algo mas elaborado.

Código Javascript:
Ver original
  1. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
  2. <html xmlns="http://www.w3.org/1999/xhtml">
  3. <head>
  4. <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
  5. <title>Documento sin título</title>
  6. </head>
  7. <script>
  8. i=0;
  9. flag=0;
  10.  
  11. window.onload=function(event){
  12.     window.onclick=rectangulo; 
  13.     }
  14. function rectangulo(event){
  15. if(flag==0){
  16. var x=event.clientX;
  17. var y=event.clientY;
  18. var div=document.createElement("div");
  19. div.id=i
  20. i++;
  21. div.style.position="absolute";
  22. div.style.zIndex=i;
  23. div.style.left=x+"px";
  24. div.style.top=y+"px";
  25. div.style.backgroundColor="#000";
  26. document.body.appendChild(div);
  27. window.onmousemove=function(event){
  28. div.style.width=(event.clientX-x)+"px";
  29. div.style.height=(event.clientY-y)+"px";
  30. }
  31. flag=1;
  32. }
  33. else{flag=0; window.onmousemove=false;
  34.     }
  35.     }
  36.  
  37.  
  38. </script>
  39. <body>
  40. </body>
  41. </html>


Si no entiendes algo o necesitas mas ayuda no dudes en preguntar.