Shake animation not for?

0

I have a problem with the shake animation, once it starts, I can not get it to stop

var shakeit = null;
function abre(a){
    clearInterval(shakeit);
}
function fecha(){
    var shakeit = setInterval(function(){
        $(".left_noti2").effect("shake",{direction:"up", distance:"5", times: "2"});
    }, 3000);
}

Once I press the button to close the div, I would like the button to have the shake effect but barely open it again, I would like it to stop, but the code I have is not working, is there a solution?

    
asked by anonymous 20.09.2017 / 20:51

1 answer

0

The error is at line var shakeit = setInterval(function(){ , where you are defining a shakeit variable within the scope of the fecha() function, so the abre() function does not have access.

Here's the catchphrase:

var shakeit = null;

function abre() {
  clearInterval(shakeit);
}

function fecha() {
  shakeit = setInterval(function() {
    $(".left_noti2").effect("shake", {
      direction: "up",
      distance: "5",
      times: "2"
    });
  }, 3000);
}

$('#btnAbre').click(function() {
  abre();
});

$('#btnFecha').click(function() {
  fecha();
});
.left_noti2 {
  width: 200px;
  height: 200px;
  background-color: blue;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script><scriptsrc="https://code.jquery.com/ui/1.12.0/jquery-ui.min.js" integrity="sha256-eGE6blurk5sHj+rmkfsGYeKyZx3M4bG+ZlFyA7Kns7E=" crossorigin="anonymous"></script>

<button type="button" id="btnAbre">Parar</button>
<button type="button" id="btnFecha">Agitar</button>

<div class="left_noti2"></div>
    
21.09.2017 / 18:14