Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8292097
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T13:21:18+00:00 2026-06-08T13:21:18+00:00

I am trying out JQuery for the first time. I decided to create an

  • 0

I am trying out JQuery for the first time.

I decided to create an animated menu and I am having a problem using marginTop (and paddingTop). 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.

I can get the menu to animate using 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.

Here is a link to my jsFiddle code where you can see and play with my code.
You will notice that the “wave” function does not work but the “waveLeft” function does.

Here is the markup for the menu:

<div id="menucontainer">
  <ul id="menu">
    <li class="menu-element">
      <a href="/">Home</a> 
      <span style="color: White; font-size: 2em;">|</span>
    </li>
    <li class="menu-element">
      <a href="/Home/About">About</a> 
      <span style="color: White; font-size: 2em;">| </span>
    </li>
    <li class="menu-element">
      <a href="/Artists">Artists</a> 
      <span style="color: White; font-size: 2em;">|</span>
    </li>
    <li class="menu-element">
      <a href="/Releases">Releases</a> 
    </li>
  </ul>
</div>

Here’s my CSS code for the menu (it goes on a black background)

ul#menu
{
    padding: 0;
    margin: 0;
    font-family: "Lucida Console" , Monaco, monospace;
}

ul#menu li.menu-element
{
    display: inline;
    list-style: none;
}

ul#menu li#greeting
{
    padding: 10px 20px;
    text-decoration: none;
    line-height: 2.8em;
    color: #5C87B2;
    font-family: "Lucida Console" , Monaco, monospace;
}

ul#menu li.menu-element a
{
    padding: 10px 20px;
    font-family: "Lucida Console" , Monaco, monospace;
    text-decoration: none;
    line-height: 2.8em;
    color: #5C87B2;
    font-size: 2em;
}

ul#menu li.menu-element a:hover
{
    color: #fff;
    text-decoration: none;
}

ul#menu li.menu-element a:active
{
    color: #b5d6f9;
    text-decoration: none;
}

ul#menu li.selected a
{
    background-color: #fff;
    color: #000;
}

Here is my working JavaScript:

$(document).ready(function () {
    menuWave("#menu", 25, 15, 150, .8);
});

function menuWave(menu_id, pad_down, pad_up, time, multiplier) {
     var list_elements = menu_id + " li.menu-element";
    var link_elements = list_elements + " a";

    var timer = 0;

    $(list_elements).each(function (i) {
        timer = (timer * multiplier + time);
        $(this).animate({ marginLeft: "0px" }, timer);
        $(this).animate({ marginLeft: "-15px" }, timer);
        $(this).animate({ marginLeft: "0px" }, timer);
    });


    $(link_elements).each(function (i) {
        $(this).hover(
    function () {
        $(this).animate({ paddingLeft: pad_down }, 150);
    },
    function () {
        $(this).animate({ paddingLeft: pad_up }, 150);
    });
    });

}

Here is my Not Working code:

$(document).ready(function () {
    menuWave("#menu", 25, 15, 150, .8);
});

function menuWave(menu_id, pad_down, pad_up, time, multiplier) {
     var list_elements = menu_id + " li.menu-element";
    var link_elements = list_elements + " a";

    var timer = 0;

    $(list_elements).each(function (i) {
        timer = (timer * multiplier + time);
        $(this).animate({ marginTop: "0px" }, timer);
        $(this).animate({ marginTop: "-15px" }, timer);
        $(this).animate({ marginTop: "0px" }, timer);
    });


    $(link_elements).each(function (i) {
        $(this).hover(
            function () {
                $(this).animate({ paddingTop: pad_down }, 150);
            },
            function () {
                $(this).animate({ paddingTop: pad_up }, 150);
            });
    });

}

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

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-08T13:21:19+00:00Added an answer on June 8, 2026 at 1:21 pm

    try this code in js:

    $(link_elements).each(function (i) {
        $(this).hover(
            function () {
                $(this).animate({ 'padding-top': pad_down+'px' }, 150);
            },
            function () {
                $(this).animate({ 'padding-top': pad_up+'px' }, 150);
            }
        );
    });
    

    and this code in css:

    ul#menu li.menu-element a
    {
        ...
    display: block;
    float: left;
    }
    

    try to fix the rest of the style in order to view a good result …

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying out JQuery and jqGrid for the first time to do a
I'm trying out some jQuery for the first time. My first goal is for
First time using jquery (using the out of the box 1.4.4 in MVC3 even
I'm trying-out qUnit for the first time but can't get any tests to run.
I'm trying to create one of those pop-up boxes you'll get the first time
So I'm trying out JSON for the first time. I have this Twitter API
first of all, I'm not good with jQuery and coding. I'm trying to achieve
I'm using Ajax via jQuery for the first time ever. I have an html
long time reader, first time writer here. I'm trying to figure out all possible
I'm trying to make a mobile application using jQuery Mobile and Phonegap. But first

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.