Reputation: 6111
I trying to animate listfrom left to right and vice versa,now i want when mouse hover on div list animate left to right and when mouse leave that div than it list animate right to left , can anyone help me for this.
$('.ul_div').mouseover(function () {
$('.ul_div').css({ display: 'block' });
$('.ul_div ul').animate({ left: '100px', background: '#ccc' }, 100);
});
<div class="ul_div">Hover Me<div>
<ul id='ulEle'>
<li><a href="">demo</a></li>
<li><a href="">demo</a></li>
<li><a href="">demo</a></li>
<li><a href="">demo</a></li>
</ul>
Demo Here
Upvotes: 3
Views: 8235
Reputation: 16777
CSS:
.ul_div ul {
position: absolute;
display: none
}
.ul_div {
border:2px solid Red;
position: relative;
}
Javascript:
$('.ul_div').hover(
function () {
$('.ul_div ul').css({
display: 'block'
});
$('.ul_div ul').animate({
left: '100px',
background: '#ccc'
}, 100);
},
function () {
$('.ul_div ul').animate({
left: '0',
background: '#ccc'
}, 100, function () {
$('.ul_div ul').css({
display: 'none'
});
});
});
Upvotes: 2
Reputation: 53198
You need to specify positioning on the ul
element in order to use the CSS left
and right
properties.
Update your CSS as follows:
#ulEle {
position: absolute;
}
.ul_div {
border:2px solid Red;
position: relative;
}
You should then update your jQuery code to use the hover()
function, and use the following code:
$('.ul_div').hover(function () {
$('.ul_div ul').animate({ left: '100px', background: '#ccc' }, 100);
}, function() {
$('.ul_div ul').animate({ left: '0px', background: '#ccc' }, 100);
});
Please see the updated jsFiddle for a demo.
Upvotes: 1