Philip Savenok Philip Savenok - 2 days ago 4
HTML Question

jQuery animation doesn't work for my navbar

I have a navigation menu on top of my page made out of list items. I want to apply jQuery code to make the list items to slide down one by one when my page loads...Can't get it work.

index.html

<div class="container">
<ul>
<a href="#"><li id="goFirst">Projects</li></a>
<a href="#"><li id="goSecond">Contact</li></a>
<a href="#"><li id="goThird">Blog</li></a>
</ul>
</div>


script.js

$(document).ready(function() {
$('#goFirst').animate({top: '+=75px'}, 1000);
$('#goSecond').delay(1000).animate({top: '+=75px'}, 1000);
$('#goThird').delay(2000).animate({top: '+=75px'}, 1000);
});

Answer

Use marginTop instead of top.

$(document).ready(function() {
  $('#goFirst').animate({
    marginTop: '+=75px'
  }, 1000);
  $('#goSecond').delay(1000).animate({
    marginTop: '+=75px'
  }, 1000);
  $('#goThird').delay(2000).animate({
    marginTop: '+=75px'
  }, 1000);
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
<div class="container">
  <ul>
    <li id="goFirst">
      <a href="#">Projects</a>
    </li>
    <li id="goSecond">
      <a href="#">Contact</a>
    </li>
    <li id="goThird">
      <a href="#">Blog</a>
    </li>
  </ul>
</div>

Comments