How can I make jQuery animations smoother?

jQueryWeb DevelopmentFront End Technology

To make jQuery animations smoother use the easing library. Use the animation speed properly to form it a perfect animation for the web page. Do not speed up animation and you should know where to stop it while using animate().

For an example, set a button, that fades out on click and displays a textarea:

<button class="btn" id="answer">Add answer</button>

The following is the textarea that generates showing smoother animation using animation() and fadeout():

<div class="middle">
<textarea id="question-content"></textarea>

You can try to run the following code to make jQuery animation smoother:


 Live Demo

<!DOCTYPE html>
   <script src=""></script>
         $('body').on('click', '#answer', function() {
            var container = $('.new-answer');
            container.css('opacity', '0');
            $(this).fadeOut('fast', function() {
               container.animate({ height: "200px",
               opacity: 1}).animate({ height: "170px" });

.btn {
   width: 150px;
   height: 40px;
   text-decoration: none;
.new-answer {
   background: none repeat scroll 0 0 #00FFFF;
   border: 2px solid #94ACBE;
   border-radius: 5px 5px 5px 5px;
   margin-bottom: 40px;
.new-answer .middle, .top {
   padding: 0 10px;
.new-answer textarea {
   color: #000080;
   font: 12px;
   height: 120px;
   padding: 2px;
   width: 100%;
<button class="btn" id="answer">Add answer</button>
<div class="new-answer" hidden="true">
<div class="top">
<span>Add a new answer below</span>
<div class="middle">
   <textarea id="question-content"></textarea>

Published on 20-Aug-2018 12:42:41