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

236
Vistas
jquery 3.6.0 animate width to specific size not working

I have this jsfiddle:

$('.btn').click(function() {
  if ($('nav').hasClass('open')) {
    $('nav').removeClass('open');
    $('.hide').animate({
      width: '508px'
    });
  } else {
    $('nav').addClass('open');
    $('.hide').animate({
      width: 'toggle'
    });
  }
})

where I'm trying to get a side navbar to just show icons then when the button is clicked to animate to get a specific width.

While the toggling works and it's getting the desired width, it's not animated.

Any ideas?

about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

Consider the following.

https://jsfiddle.net/Twisty/ck7y19rz/6/

JavaScript

$('.btn').click(function(event) {
  $("nav").toggleClass("open");
  if ($("nav").hasClass("open")) {
    $(".hide").show().animate({
      width: "580px"
    });
  } else {
    $(".hide").animate({
      width: "0px"
    }, function() {
      $(".hide").hide();
    });
  }
});

This is largely just cleaned up code. As was commented, when you animate back to the original size, it must use a Width value, not a keyword, like auto. I also added .show() and .hide() to ensure the state of the element is returned to the expected visible state.

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