Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

308
Vistas
Why does div.width not work when using clearInterval?

I made a square that moves to the end of the width of its container using set and clearInterval. If I add the width as a number it's stopped but when I add the container.width it's not working:

var container = document.getElementById('container')
var square = document.getElementById('mySquare')

function theAll(sq,con){
var pos = 0;
var moving = setInterval(move,10)      
function move(){
  if(pos == con.width){
        clearInterval(moving)}
  else{
  pos++
  sq.style.left=pos + "px";}
  }}

  theAll(square,container)

#container{
  font-size: 100%;
  font-family: Comic Sans MS;
  background-color: blanchedalmond;
 border-radius: 5px;
 padding: 0; 
  width: 100%;
  height: 60%; 
  display: flex;
  flex-direction: column;    
  }
  #mySquare{
  width: 5%;
  height: 5%;
  background-color: blueviolet;
  position: relative;
  }
about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

You can try to replace con.width with con.offsetWidth

Example https://codepen.io/julien180/pen/JjJvqEd?editors=1111

about 4 years ago · Juan Pablo Isaza Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda