Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

230
Views
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 answers
Answer question

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 Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!