473,503 Members | 1,300 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

JQuery Animate using marginTop

Frinavale
9,735 Recognized Expert Moderator Expert
I am finally trying out JQuery!

I decided to create an animated menu and I am having a problem using marginTop (and paddingTop). I can get the menu to do something with marginLeft and paddingLeft but it's not the effect I'm looking for and I'm really curious to know what I'm doing wrong.

I am trying to achieve a "wave" type effect for my menu items when the page loads. When the user hovers over the items, I want them to raise slightly.


Here is the markup for the menu:
Expand|Select|Wrap|Line Numbers
  1. <div id="menucontainer">
  2.   <ul id="menu">
  3.     <li class="menu-element">
  4.       <a href="/">Home</a> 
  5.       <span style="color: White; font-size: 2em;">|</span>
  6.     </li>
  7.     <li class="menu-element">
  8.       <a href="/Home/About">About</a> 
  9.       <span style="color: White; font-size: 2em;">| </span>
  10.     </li>
  11.     <li class="menu-element">
  12.       <a href="/Artists">Artists</a> 
  13.       <span style="color: White; font-size: 2em;">|</span>
  14.     </li>
  15.     <li class="menu-element">
  16.       <a href="/Releases">Releases</a> 
  17.     </li>
  18.   </ul>
  19. </div>
Here's my CSS code for the menu:
Expand|Select|Wrap|Line Numbers
  1. body
  2. {
  3.     background-color:black;
  4. }
  5. ul#menu
  6. {
  7.     padding: 0;
  8.     margin: 0;
  9.     font-family: "Lucida Console" , Monaco, monospace;
  10. }
  11.  
  12. ul#menu li.menu-element
  13. {
  14.     display: inline;
  15.     list-style: none;
  16. }
  17.  
  18. ul#menu li#greeting
  19. {
  20.     padding: 10px 20px;
  21.     text-decoration: none;
  22.     line-height: 2.8em;
  23.     color: #5C87B2;
  24.     font-family: "Lucida Console" , Monaco, monospace;
  25. }
  26.  
  27. ul#menu li.menu-element a
  28. {
  29.     padding: 10px 20px;
  30.     font-family: "Lucida Console" , Monaco, monospace;
  31.     text-decoration: none;
  32.     line-height: 2.8em;
  33.     color: #5C87B2;
  34.     font-size: 2em;
  35. }
  36.  
  37. ul#menu li.menu-element a:hover
  38. {
  39.     color: #fff;
  40.     text-decoration: none;
  41. }
  42.  
  43. ul#menu li.menu-element a:active
  44. {
  45.     color: #b5d6f9;
  46.     text-decoration: none;
  47. }
  48.  
  49. ul#menu li.selected a
  50. {
  51.     background-color: #fff;
  52.     color: #000;
  53. }
Here is my working javascript:
Expand|Select|Wrap|Line Numbers
  1. $(document).ready(function () {
  2.     slide("#menu", 25, 15, 150, .8);
  3. });
  4.  
  5. function slide(navigation_id, pad_out, pad_in, time, multiplier) {
  6.     // creates the target paths
  7.     var list_elements = navigation_id + " li.menu-element";
  8.     var link_elements = list_elements + " a";
  9.  
  10.     var timer = 0; // initiate timer for the  animation
  11.  
  12.     // creates an animation for all list elements 
  13.     $(list_elements).each(function (i) {
  14.         timer = (timer * multiplier + time); // updates timer
  15.         $(this).animate({ marginLeft: "0px" }, timer);
  16.         $(this).animate({ marginLeft: "15px" }, timer);
  17.         $(this).animate({ marginLeft: "0px" }, timer);
  18.     });
  19.  
  20.     // creates the animation for all link elements         
  21.     $(link_elements).each(function (i) {
  22.         $(this).hover(
  23.     function () {
  24.         $(this).animate({ paddingLeft: pad_out }, 150);
  25.     },
  26.     function () {
  27.         $(this).animate({ paddingLeft: pad_in }, 150);
  28.     });
  29.     });
  30.  
  31. }
The marginLeft and paddingLeft animations work fine.

But if I switch marginLeft to marginTop and paddingLeft to paddingTop it doesn't work.



Thanks for your help

-Frinny
Jul 24 '12 #1
2 4873
Frinavale
9,735 Recognized Expert Moderator Expert
I created a jsFiddle account and saved my example.
You'll notice that the wave function does not work, but the waveLeft function does.

Here's the link to my jsFiddle code demonstrating the problem.
Jul 26 '12 #2
Frinavale
9,735 Recognized Expert Moderator Expert
Well apparently all I had to do was change the style from:
Expand|Select|Wrap|Line Numbers
  1. ul#menu li.menu-element
  2. {
  3.     display: inline;
  4.     list-style: none;
  5. }
To
Expand|Select|Wrap|Line Numbers
  1. ul#menu li.menu-element
  2. {
  3.     display: block;
  4.     float:left;
  5.     list-style: none;
  6. }
And the animation worked fine.

-Frinny
Jul 26 '12 #3

Sign in to post your reply or Sign up for a free account.

Similar topics

1
9526
by: Rich | last post by:
Hello, I found some code for printing a report (.rdlc) file without using the ReportViewer control. This code prints in the Portrait orientation which I presume is the default orientation. I...
0
2348
by: thirunavukarasukm | last post by:
Hai.... To print Html page using PrintDialog and Print Document i am created one windows appication.. the windows application have many pages in my booking page i have two buttons one...
1
1491
by: artev | last post by:
var_cont. find('.style1').src(current.src).css({ opacity: 1 }).animate({ opacity: 0.6}).end(). is possible to have 2nd opacity with no use of .animate? and which are a list of animates's...
0
1438
by: liz0001 | last post by:
I have seen many examples on how to use the .load() function to load in static elements, but I am trying to load a dynamic element, specifically a scrollable. I have gotten it to the point where:...
3
2960
by: metaphysics | last post by:
http://wexcode.com/portfolio.php For some reason, this page doesn't work in IE, but seems to work fine in all other browsers. Can anyone identify why this isn't working in IE? Thanks. ...
1
2424
Mads Klitgaard
by: Mads Klitgaard | last post by:
I have a sort of sidebar on my website, which has to scroll down together with the user so that it is always in the view. The code I'm using now is actually working fine however there is one...
1
2351
oranoos3000
by: oranoos3000 | last post by:
hi my question is about jquery string show or hide in css that is set inside jquery method animate , are special for some css property or can be set for any css that is set inside animate method...
0
919
by: Gunasegar | last post by:
Greeting to all !!!!! am new to jquery and using it well... it sounds good... the problem is when i using ajax post method and append to the original page, the javascript i loaded in the...
1
1571
by: Sketchiie | last post by:
if(isset($_POST)) { mysql_query("UPDATE Blad1 SET Naam ='$naamveld', Inkoop='$inkoopveld', Verkoopprijs='$verkoopveld', Aantal ='$aantalveld', Verkocht= '$verkochtveld' WHERE id = '$id'") ...
1
1821
ilya Kraft
by: ilya Kraft | last post by:
Hello, I'm struggling to find out how to configure following script to start on mouse click instead of hover. I tried replacing .hover with .focus .click .mouseover but it did not work. ...
0
7203
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
7089
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
7282
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
7339
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
6995
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
7463
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
3168
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
1515
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
1
738
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.