0

I want to make some list items bounce on hover, but can't seem to figure out why it's not working. This is the link to the coding on jsfiddle: http://jsfiddle.net/wrdweaver6/amhJK/

Here is the code that I am using in my html head:

<head>
     <script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jqueryui/1.8.16/jquery-ui.min.js"></script>

     <script type="text/javascript">
       $(document).ready(function(){
           $('#nav > li').hover(function() {
              $(this).effect('bounce',{times: 2},'slow');
           });
       });
     </script>   
</head>

Here is the body:

 <body>

  <div id="nav">

    <ul>
        <li>Word Lists</li>
        <li>Games</li>
        <li>Stories</li>
        <li>Parents</li>
        <li>Email</li>
    </ul>

  </div>
</body>
Ionică Bizău
  • 109,027
  • 88
  • 289
  • 474

4 Answers4

2

Two things I noticed:

  • One your selector is wrong, it should just be $('#nav li') as li is not a direct child element of the #nav
  • Secondly you need to include the jquery UI JS, pretty sure the animations won't work without the JS file.
Ionică Bizău
  • 109,027
  • 88
  • 289
  • 474
JanR
  • 6,052
  • 3
  • 23
  • 30
  • I downvoted because the jQuery UI CSS is not needed. Only jQuery UI js is needed in this case. – Ionică Bizău Jul 24 '13 at 06:48
  • Fair enough, I was under the assumption UI was using keyframe CSS animations, but never really looked into it to be honest :) I just always link the CSS – JanR Jul 25 '13 at 00:40
2

Try the following Js fiddle

http://jsfiddle.net/arunberti/Dy6h7/

$(document).ready(function(){
  $('li a').hover(function() { 
     $(this).parent().effect("bounce", { times:3 }, 'normal');
   }, function () {
     $(this).parent().effect("bounce", { times:3 }, 'normal');
   });
});

Also check the following image that you didint add Jquery UI

enter image description here

Ionică Bizău
  • 109,027
  • 88
  • 289
  • 474
Arun Bertil
  • 4,598
  • 4
  • 33
  • 59
  • Okay. Nevermind. I was referring to the answer above yours. Thank you so much for your help! – BliaKong Lee Jul 24 '13 at 05:07
  • @bliakong lee were you able to resolve the issue?if this helped dont forgot to mark as answer coz some ppl who have answered this post seems to downvote – Arun Bertil Jul 24 '13 at 05:16
  • @ArunBertil Your jsfiddle was what I wanted, since it did not cause the li elements to stack on top of each other like mine, but I am concerned that the coding will cause an html error when validating since you have your a tags on the inside of your li tags. I have to run my coding through W3c's html validation service for the class that I am taking. – BliaKong Lee Jul 24 '13 at 05:30