how to make inlay controls toggle with jquery?
i have an image. if you mouseover it, the controls for next img and previous image appear, displayed on the image (moved there via css). if i mouseout the image the controls, shell disappear.
the problem is, if i mouseover one of the controls i mouseout the image and the controls disappear :-(
how can i handle that? i tryed something like that, but it doesn't do the trick: var control = false;
$('.detail_img').bind('mouseover', function(){开发者_开发技巧
$('.gal_control').fadeIn(200);
});
$('.detail_img').bind('mouseout', function(){
if(!control) $('.gal_control').fadeOut(400);
});
$('.gal_control').bind('mouseover', function(){
control = true;
});
$('.gal_control').bind('mouseout', function(){
control = false;
});
thanks for helping me
the html ... for all with no fantasy :-)
<div class="rollover_left gal_control"></div>
<div class="rollover_right gal_control"></div>
<img class="detail_img" id="detail_img" src...>
UPDATE
var control = false;
$('.detail_img').bind('mouseover', function(){
control = true;
$('.gal_control').fadeIn(200);
});
$('.detail_img').bind('mouseout', function(){
control = false;
});
$('body').bind('mouseover', function(){
if(!control) $('.gal_control').fadeOut(400);
});
$('.gal_control').bind('mouseover', function(){
control = true;
});
$('.gal_control').bind('mouseout', function(){
control = false;
});
i mean, this does the trick now, but is there a better way? can i optimze those lines?
I'd try one or both of the following:
- Wrap both the image and the controls in a
<div>
, and attach the mouse events to the div instead of the image - Try using the
mouseenter
andmouseleave
events instead ofmouseover
/mouseout
精彩评论