lundi 31 août 2015

Animate a div sliding with a toggle button

I can't seem to figure out how to animate my div sliding with a toggle button.

I tried using variables but I have multiple of these and I am creating too many variables to keep track of the clicks on each of them.

$(document).ready(function() {
  
  $('#toggle-sidebar').click(function() {
    $('#sidebar').animate({
      left: '200'
    }, 500);
  });
  
});
#sidebar {
  position: absolute;
  top: 0;
  left: 0;
  width: 20em;
  height: 70vh;
  background:#333;
}

#toggle-sidebar {
  float: right;
}
<script src="http://ift.tt/1oMJErh"></script>

<div id="sidebar"></div>

<a href="#" id="toggle-sidebar">Toggle</a>


via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire