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
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
Share Improve this question edited Sep 9, 2013 at 10:54 Rory McCrossan 338k41 gold badges320 silver badges351 bronze badges asked Sep 9, 2013 at 10:51 S. S. RawatS. S. Rawat 6,1314 gold badges44 silver badges59 bronze badges 1- 1 FYI please include all code in your question. A link to a fiddle is great, but it will be useless if jsfiddle goes offline. – Rory McCrossan Commented Sep 9, 2013 at 10:54
2 Answers
Reset to default 2jsFiddle Demo
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'
});
});
});
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.
发布者:admin,转转请注明出处:http://www.yc00.com/questions/1744963690a4603543.html
评论列表(0条)