Reputation: 3
Hi guyz i got a mouseover event and mouseout event. is this the right way ?, or is there a better/cleaner way..
i made a demo of this
$(".containerslide").mouseover(function(){
$(this).find(".slide").stop().animate({'margin-left': '0',}, 500)
});
$(".containerslide").mouseout(function(){
$(this).find(".slide").stop().animate({'margin-left': '-320px',}, 500)
});
Upvotes: 0
Views: 262
Reputation: 74420
You could use hover
in/out handler:
$(".containerslide").hover(function (e) {
$(this).find(".slide").stop().animate({
marginLeft: e.originalEvent.type === "mouseover" ? 0 : -320,
}, 500)
});
Or using only CSS:
.slide {
margin-left:-320px;
position: absolute;
background: yellow;
width: 320px;
height: 250px;
-webkit-transition: margin-left .5s;
transition: margin-left .5s;
}
.containerslide:hover .slide{
margin-left:0;
-webkit-transition: margin-left .5s;
transition: margin-left .5s;
}
Upvotes: 1
Reputation: 38102
You can use .hover() instead:
Bind two handlers to the matched elements, to be executed when the mouse pointer enters and leaves the elements.
$(".containerslide").hover(function () {
$(this).find(".slide").stop().animate({
'margin-left': '0',
}, 500)
}, function () {
$(this).find(".slide").stop().animate({
'margin-left': '-320px',
}, 500);
});
Upvotes: 0