Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

232
Visualizações
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 Respostas
Responde à pergunta

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 Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda