简体   繁体   中英

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

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> 

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM