Reputation: 91
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?
Upvotes: 2
Views: 1109
Reputation: 7315
First of all you can not do this animation with z-index
, you should create a mask area with css overflow:hidden
property and hide the animating objects with position
.
Second thing, you can not animate an object right
when that object's css got left
property, 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:
$('#menu_seo li').bind({
mouseenter: function() {
$(this).children('span').stop().animate({'right':'70px'},200);
},
mouseleave: function() {
$(this).children('span').stop().animate({'right':'-50px'},200);
}
});
css:
#left_aside {
overflow:hidden;
float:left;
width:230px;
height:900px;
background-color:#f2dada;
}
ul#menu_seo li span {
height:50px;
width:50px;
position:absolute;
cursor:pointer;
right:-50px;
}
Upvotes: 2