Prevent Double Click on Div and Detect Mouse Scroll

Add a timeout to prevent a double click. Detect a mouse wheel scroll on all other divs except the one that is animated.

by bmarsh123

HTML

<script src="http://code.jquery.com/jquery-1.9.1.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

jQuery('.flip').click(function() { 
    var $this = jQuery(this);
    if ($this.data('activated')) return false;  // Pending, return
    
    $this.data('activated', true);
    setTimeout(function() {
        $this.data('activated', false)
    }, 1500); // Time to wait until next click can occur
    
    doFlip(); // Call whatever funtion you want
    return false; 
});

function doFlip() {
    if ($('.flip').find('.card').hasClass('flipped')) {
        $('.flip').find('.card').removeClass('flipped');
    } else {
        $('.flip').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;
 });