开发者

how to make inlay controls toggle with jquery?

开发者 https://www.devze.com 2023-01-08 02:21 出处:网络
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.

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:

  1. Wrap both the image and the controls in a <div>, and attach the mouse events to the div instead of the image
  2. Try using the mouseenter and mouseleave events instead of mouseover/mouseout
0

精彩评论

暂无评论...
验证码 换一张
取 消