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

157
Views
jQuery start and stop animation with the same button

Jquery. Is there a way to start an animation and stop that animation using the same button?

js:

   $('<div>').css({
        'width':'200px',
        'height':'200px',
        'background':'red'
    }).appendTo('body')
    $('<button>').appendTo('body').text('Click').click(function(){
        $('div').animate({
            'height': '250px'
        })
    })
    
    $('button').on('click',function(){
        $('div').animate({'height':'350px'})
    })
about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

Look at this code;

<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js"></script>
<style type="text/css">
    div {
    background-color: #ffeecc;
    width: 100px;
    height: 100px;
    }
</style>
<script type="text/javascript">
    $(function () {
    var starts = false;

    $("#btnStart").click(function () {
        if (!starts) {
        start();
        } else {
        stop();
        }
    });

    function start() {
        starts = true;
        $("#btnStart").val("Stop");
        $("#divOne").animate(
        {
            width: "200px",
            height: "300px",
        },
        5000
        );
    }

    function stop() {
        starts = false;
        $("#btnStart").val("Start");
        $("#divOne").stop();
    }
    });
</script>
<input id="btnStart" type="button" value="Start" />
<br/><br/>
<div id="divOne" />
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!