(SO - 22049177) Reveal part of Blurred image where mouse is hovered
by Jessel John
HTML
<script src="https://rawgithub.com/GianlucaGuarini/vague.js/master/Vague.js"></script>
<br/><br/><br/>
<div id="container">
<img src="http://i.imgur.com/IGKVr8r.png" alt="follow picture" />
<div class="revealPic"></div>
</div>
<div id="show" style="position:fixed;top:0px;left:0px;"></div>
CSS
html,body{
margin:0px;
padding:0px;
}
#container{
position:relative;
margin-left:100px;
display:inline-block;
}
.revealPic{
position:absolute;
top:0px;
left:0px;
background-image:url('http://i.imgur.com/IGKVr8r.png');
background-color:white;
background-position:0px 0px;
background-repeat:no-repeat;
width:50px;
height:50px;
/*making div circular*/
border-radius:50%;
-moz-border-radius:50%;
-webkit-border-radius:50%;
-ms-border-radius:50%;
-khtml-border-radius: 50%;
}
JavaScript
var hgt = $('#container'),
bgt = $('#container .revealPic');
var bgtHalfW = bgt.width()/2,
bgtHalfH = bgt.height()/2;
/**Change position of .revealPic and background-image within it on mousemove over container**/
hgt.mousemove(function(event){
event.preventDefault();
bgt.show();
var scrollLeftPos = $(window).scrollLeft(),
scrollTopPos = $(window).scrollTop(),
offsetLft = hgt.offset().left,
offsetTp = hgt.offset().top;
var upX=event.clientX;
var upY=event.clientY;
bgt.css({backgroundPosition : ''+(offsetLft-upX+bgtHalfW-scrollLeftPos)+'px '+(offsetTp-upY+bgtHalfH-scrollTopPos)+'px',top:''+(-offsetTp+upY-bgtHalfH+scrollTopPos)+'px',left:''+(-offsetLft+upX-bgtHalfW+scrollLeftPos)+'px'});
});
/*********************************************/
/*Hide .revealPic div on mouseout*/
hgt.mouseout(function(){
bgt.hide();
});
/*********************************/
/*Using vague.js to make blurred image*/
var vague = $("#container img").Vague({intensity:10});
vague.blur();
/**************************************/