$(document).keydown(function(e) {
   if (e.keyCode == 27) {
      closeall();
   }
});
function closeall() {
    $('.jq_bt_opacity').hide();
    $('.jq_bt_fan_3d').hide();
}
$(document).click(function(event) {
 if ($(event.target).closest('.jq_bt_opacity').length) return;
 if ($(event.target).closest('.jq_bt_fan_3d').length) return;
 closeall();
 event.stopPropagation();
});

$('body').on('click', '.jq_bt_3d_img', function() {
    $('.jq_bt_fan_3d').css('display','block');
    opacshow();
    return false;
}).on('click','.jq_bt_close',function(){
    closeall();
});
$('.jq_bt_mechta_opacity').on("click", function () {
    closeall();
});

footer.php

<div class="jq_bt_opacity idnone"></div>

css

.jq_bt_opacity{
    position: absolute;
    background-color: black;
    display: none;
    height: 100%;
    width: 100%;
    left: 0;
    top: 0;
    opacity: 0.5;
    -ms-filter: "alpha(opacity=50)";
    z-index: 9;
}