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

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

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 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