Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get mouseover event of an element under an overlayed div

I have four div elements and on mouseover the selected div will get zoomed. But i need to get the mouseover event of the remaining three underlayed divs even when the other one is overlayed, so that i can make the earlier one out of zoom and the currently hovered one zoomed.

Please consider my fiddle: http://jsfiddle.net/aniprasanth/7jFGH/1/

HTML code goes like this

<div id="main_window">
                <div class="multi-window">
                    <div class="zoomer tile">
                        <img src="images/img1.jpg" width="207" height="138" />
                    </div>
                 </div>
              <div class="multi-window">
                    <div class="zoomer tile">
                        <img src="images/img2.jpg" width="207" height="138" />
                    </div>
                 </div>
             <div class="multi-window">
                    <div class="zoomer tile">
                        <img src="images/img3.jpg" width="207" height="138" />
                    </div>
                 </div>
              <div class="multi-window">
                    <div class="zoomer tile">
                        <img src="images/img4.jpg" width="207" height="138" />
                    </div>
                 </div>
            </div>

CSS Goes like this:

#main_right #main_window {
height: 320px;
width: 460px;
margin-right: auto;
margin-left: auto;
margin-top: 20px;
position: relative;

}
.multi-window {
height: 150px;
width: 218px;
float: left;
margin-right: 11px;
margin-bottom: 10px;
cursor: pointer;
}
.zoomer {
height: 140px;
width: 208px;
cursor:pointer;
}
.zoom {
height: 301px;
width: 450px;
float:none;
margin:0px;
cursor:pointer;
position:absolute;
left:0;
top:0;
background-color:#FFF;
}
.multi-window img {
width:100% !important;
height:100% !important;
}

and finally the script:

$('.zoomer').on('mouseenter',function(e){
        $(this).addClass('zoom').removeClass('zoomer');
        $('.zoom img').css({
            'width':'100%',
            'height':'100%'
            });

            $(this).bind('mouseleave click', function(){

                $(this).removeClass('zoom').addClass('zoomer');
                $('.zoomer').removeClass('zoomer'); 


                });
        });
like image 895
Prasanth K C Avatar asked Feb 12 '13 10:02

Prasanth K C


People also ask

Can hover be applied on Div?

You can apply :hover styles to any renderable element on a page. IE6 only supports that pseudo-class on links though.

Is mouseover an event?

The onmouseover event occurs when the mouse pointer is moved onto an element, or onto one of its children. Tip: This event is often used together with the onmouseout event, which occurs when a user moves the mouse pointer out of an element.

Is the mouseover event fired?

The mouseover event is fired at an Element when a pointing device (such as a mouse or trackpad) is used to move the cursor onto the element or one of its child elements.


1 Answers

Use this CSS property for the overlay Div.

pointer-events: none

This will disable all click events on that div and will pass all the click events to the layer beneath it.

like image 154
Anubhav Gupta Avatar answered Nov 10 '22 00:11

Anubhav Gupta