(SO - 22049177) Reveal part of transparent overlayed image where mouse is hovered
by Jessel John
HTML
<br/><br/><br/>
<div id="container">
<div class="blurPic"></div>
<img src="http://i.imgur.com/IGKVr8r.png" alt="follow picture" />
</div>
CSS
html,body{
margin:0px;
padding:0px;
}
#container{
position:relative;
margin-left:100px;
}
.blurPic{
position:absolute;
top:0px;
left:0px;
width:0px;
height:0px;
box-shadow:0px 0px 0px 160px white inset;
-moz-box-shadow:0px 0px 0px 160px white inset;
-webkit-box-shadow:0px 0px 0px 160px white inset;
-ms-box-shadow:0px 0px 0px 160px white inset;
opacity:0.9;
filter:alpha(opacity=0.9); /* For IE8 and earlier */
}
JavaScript
/**Give equal width and height as <img> to .blurPic**/
var hgt = $('.blurPic').width($('#container img').width());
$('.blurPic').height($('#container img').height());
/*****************************************************/
/*******Get shadow values*****/
var result = $('.blurPic').css('boxShadow').match(/(-?\d+px)|(rgb\(.+\))/g)
var color = result[0],
y = result[1],
x = result[2],
blur = result[3];
/******************************/
/**Change box-shadow on mousemove over image**/
var blurStartW = hgt.width()/2;
var blurStartH = hgt.height()/2;
$('.blurPic').mousemove(function(event){
event.preventDefault();
var scrollLeftPos = $(window).scrollLeft(),
scrollTopPos = $(window).scrollTop(),
offsetLft = hgt.offset().left,
offsetTp = hgt.offset().top;
var upX=event.clientX;
var upY=event.clientY;
$(this).css({boxShadow : ''+(-offsetLft+upX-blurStartW+scrollLeftPos)+'px '+(-offsetTp+upY-blurStartH+scrollTopPos)+'px 20px 100px white inset'});
});
/*********************************************/
/***reset box-shadow on mouseout***/
$('.blurPic').mouseout(function(){
$(this).css({boxShadow : '0px 0px 0px 160px white inset'});
});
/**********************************/