Reputation: 12345
I have this small script that shows a caption for a img when it is moused over.
$("#v1").mouseover(function()
{
$("#vc1").fadeIn("slow");
});
How can I expand on this so that the caption #vc1
fades back out when the icon #v1
is not moused over?
Upvotes: 1
Views: 234
Reputation: 125538
$("#v1")
.mouseover(function() {
$("#vc1").fadeIn("slow");
})
.mouseout(function() {
$("#vc1").fadeOut("slow");
});
Might consider using hover, which is essentially mouseenter
and mouseleave
$("#v1")
.hover(
function() {
$("#vc1").fadeIn("slow");
},
function() {
$("#vc1").fadeOut("slow");
});
The difference is that mouseover
and mouseout
will fire when you move into a child element of the element to which the event handler is attached, whereas mouseenter
and mouseleave
a.k.a. hover
won't. This may not be a problem if the element to which you're attaching doesn't have children.
Upvotes: 2
Reputation: 103155
You can use the hover function.
$("#v1").hover(function(){
$("#vc1").fadeIn("slow");
}, function(){
$("#vc1").fadeOut("slow");
});
Upvotes: 0
Reputation: 41232
This should do the work:
$("#v1").hover(function()
{
$("#vc1").fadeIn("slow");
}, function( )
{
$("#vc1").fadeOut("slow");
});
And htt://api.jquery.com is nice resource which can help a lot in the future.
Upvotes: 2
Reputation: 4360
You can use mouseout
together with mouseover
(or use mouseenter
and mouseleave
instead, depending on what behaviour you want when the mouse is in a child of #v1
).
Upvotes: 0