Prasath 1992 Prasath 1992 - 4 months ago 9
HTML Question

How to add jquery bounce animation

Bouncing of menu while

onload




$(document).ready(function () {
$("ul.main_menu li").on("load", function (){
$(this).show().animate({ marginTop: "80px" }, 1500 )
.animate({ marginTop: "40px" }, 800 );
});

});

/*less file*/
.main_menu {
display: inline;
li {
float: left;
list-style: none;
margin-left: 32px;
position: relative;
padding-bottom: 5px;
&:first-child {
margin-left: 5px;
}
}
a {
text-decoration: none;
color: @color_1;
font-size: 14px;
text-transform: uppercase;
outline: none;
}
li.active {
&:focus {
border-bottom: 2px solid #C80813;
}
&:active {
border-bottom: 2px solid #C80813;
}
border-bottom: 2px solid #C80813;
&:hover {
border-bottom: 2px solid #C80813;
}
&:after {
content: '';
position: absolute;
top: 27px;
right: 43%;
border: 5px solid transparent;
border-top-color: #C80813;
}
}
}

<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<ul class="main_menu">
<li class="active"><a href="#home">Home</a></li>
<li><a href="#about" data-id="#about">About us</a></li>
<li><a href="#choose">Why choose us</a></li>
<li><a href="#services">Services</a></li>
<li><a href="#projects">Projects</a></li>
<li><a href="#contact">Contact Us</a></li>
</ul>





Bounce animation is not working

Dan Dan
Answer

Try just doing

$('ul.main_menu li').show().animate({ marginTop: "80px" }, 1500 ).animate({ marginTop: "40px" }, 800 );

This will work as you already have a $(document).ready() function so it will happen when the li components are ready to be interacted with by the browser

Working JSFiddle example

Working JSFiddle with your code

$(document).ready(function () {
    $('ul.main_menu li').show().animate({ marginTop: "80px" }, 1500 ).animate({ marginTop: "40px" }, 800 );
});
**less file**
.main_menu {
    display: inline;
    li {
        float: left;
        list-style: none;
        margin-left: 32px;
        position: relative;
        padding-bottom: 5px;
        &:first-child {
            margin-left: 5px;
        }
    }
    a {
        text-decoration: none;
        color: @color_1;
        font-size: 14px;
        text-transform: uppercase;
        outline: none;
    }
    li.active {
        &:focus {
            border-bottom: 2px solid #C80813;
        }
        &:active {
            border-bottom: 2px solid #C80813;
        }
        border-bottom: 2px solid #C80813;
        &:hover {
            border-bottom: 2px solid #C80813;
        }
        &:after {
            content: '';
            position: absolute;
            top: 27px;
            right: 43%;
            border: 5px solid transparent;
            border-top-color: #C80813;
        }
    }
}
<script type = "text/javascript" 
 src = "http://ajax.googleapis.com/ajax/libs/jquery/2.1.3/jquery.min.js"></script>

<ul class="main_menu">
    <li class="active"><a href="#home">Home</a></li>
    <li><a href="#about" data-id="#about">About us</a></li>
    <li><a href="#choose">Why choose us</a></li>
    <li><a href="#services">Services</a></li>
    <li><a href="#projects">Projects</a></li>
    <li><a href="#contact">Contact Us</a></li>
</ul>

Comments