I am trying to make an image slide out on hover and then slide back once they hover to a new link but I can’t seem to get it to work.
Here’s the JS
$(function() {
$('#menu_seo > li').hover(
function () {
var $this = $(this);
$('span',$this).stop().animate({
'right':'70px'
}).css({
'zIndex':'10'
});
},
function () {
var $this = $(this);
$('span',$this).stop().animate({
'right':'-10px'
}).css({
'zIndex':'-1'
});
}
);
});
and my CSS:
#menu_seo {
position:relative;
}
ul#menu_seo li span {
height:60px;
width:15px;
position:absolute;
z-index:-1;
cursor:pointer;
}
ul#menu_seo li span.arrowout1 {
background-image:url(../arrow.png);
top:8px;
left:230px;
}
anyone see my problem here?
First of all you can not do this animation with
z-index, you should create a mask area with cssoverflow:hiddenproperty and hide the animating objects withposition.Second thing, you can not animate an object
rightwhen that object’s css gotleftproperty, this will create a conflict and won’t work. Position values must be accurate.And i suggest you to use jQuery bind method, it is solid and you can use multiple events with this, like: click, hover, mouseenter, mouseleave.
Here is working jsFiddle: http://jsfiddle.net/ATPG9/11/
jQuery:
css: