Philip Savenok
Philip Savenok

Reputation: 5

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);
});

Upvotes: 0

Views: 28

Answers (1)

Dave
Dave

Reputation: 10924

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>

Upvotes: 1

Related Questions