Problems with mouseover and mouseout

I have an image grid, when the mouse is over any image, a larger version of this image becomes an overlay, stepping on the original image of the grid with a slightly larger version.

The mouse works great. but mouseout and mouseleave cause the larger image to instantly disappear. Whether the mouse is located or not.

        function imageSize(img){
              var theImage = new Image();
              $(theImage).load(function() {
                var imgwidth = this.width;
                var imgheight = this.height;
                var position = img.parent().position()
                var index = img.parent().index();


                ///calculate top
                var top     = (position.top -((imgheight-img.height())/2));
                var left    = (position.left -((imgwidth-img.width())/2));


                /// place image in img_pop
                var clone;
                clone = '<div class="pop_img clone'+index+'"></div>';
                $(clone).insertAfter($('BODY'));


                $('.pop_img.clone'+index+'').css({
                    'width'                 :   img.width(),
                    'height'                :   img.height(),
                    'top'                   :   position.top,
                    'left'                  :   position.left,
                    'backgroundImage'       :   'url('+theImage.src+')',
                });

                    $('.pop_img.clone'+index+'').stop().animate({
                        'height'    :   imgheight,
                        'top'       :   top,
                        'width'     :   imgwidth,
                        'left'      :   left,
                    },300,'easeInOutQuad');

              });
              theImage.src = img.attr('src');
            }

            $('.am-wrapper img').live('mouseenter',function(){
                imageSize($(this));
            });

            $('.am-wrapper img').live('mouseleave',function(){
                thisIndex = $(this).parent().index();
                $('.pop_img.clone'+thisIndex+'').fadeOut('200');
            });

Ideally, I want the overlay image to remain visible in place while the mouse is over the corresponding grid image. When the user places a mouse over another grid image, the old overlay disappears.

+3
source share
1 answer

, . . , mouseout .

. , mousemove, , div.

, mouseout .

, , , mouseenter ( ):

: http://jsfiddle.net/jtbowden/29U93/

:

  • new Image()? jQuery.
  • $(clone).insertAfter($('BODY')). body . appendTo('body').

, !

z-, , div, . , ( ).

: http://jsfiddle.net/jtbowden/S6AvH/1/

javascript, javascript.

+2

All Articles