Detecting Mouse Wheel Scroll

Use jQuery to detect mouse wheel scroll and prevent detection if pointer is in div.

by bmarsh123

HTML

<script src="http://code.jquery.com/jquery-1.9.1.js"></script>
<script src="http://www.ogonek.net/mousewheel/jQuery_mousewheel_plugin.js"></script>
<div id="mainDiv">
    <img id="usimg" src="http://geology.com/state-map/maps/usa-map.jpg" />
    <div id="backgrounddiv">
        <div class="flip"> 
            <div class="card"> 
                <div class="face front"> 
                    Front
                </div> 
                <div class="face back"> 
                    Back
                </div> 
            </div> 
        </div>
    </div>
</div>

CSS

#mainDiv {
    position: relative;
}
.flip {
  -webkit-perspective: 800;
   width: 50px;
   height: 50px;
    position: absolute;
    top: 150px;
    left: 250px;
    opacity: 0.5;
}
.flip .card.flipped {
  -webkit-transform: rotatex(-180deg);
}
.flip .card {
  width: 100%;
  height: 100%;
  -webkit-transform-style: preserve-3d;
  -webkit-transition: 0.5s;
}
.flip .card .face {
  width: 100%;
  height: 100%;
  -webkit-backface-visibility: hidden ;
  z-index: 2;
    font-family: Georgia;
    font-size: 12px;
    text-align: center;
    line-height: 50px;
}
.flip .card .front {
  z-index: 1;
    background: black;
    color: white;
    cursor: pointer;
}
.flip .card .back {
  -webkit-transform: rotatex(-180deg);
    background: blue;
    background: white;
    color: black;
    cursor: pointer;
}

JavaScript

$('.flip').click(function(){
    if ($(this).find('.card').hasClass('flipped')) {
        $(this).find('.card').removeClass('flipped');
    } else {
        $(this).find('.card').addClass('flipped');
    }
});

 // IE, Opera, Safari
 $('#usimg').bind('mousewheel', function(e){
     if(e.originalEvent.wheelDelta < 0) {
         // Scroll down
         alert('Down');
         console.log('Down');
     }else {
         // Scroll up
         alert('Up');
         console.log('Up');
     }

     // Prevent page fom scrolling
     return false;
 });

 // Firefox
 $('#usimg').bind('DOMMouseScroll', function(e){
     if(e.originalEvent.detail > 0) {
         // Scroll down
         alert('Down');
         console.log('Down');
     }else {
         // Scroll up
         alert('Up');
         console.log('Up');
     }

     // Prevent page fom scrolling
     return false;
 });