Stackoverflow - How to make a circular Div in Chrome?
http://stackoverflow.com/q/8763620/918414
by gopi1410
HTML
<div id="image-frame">
<img id="image" src="http://thinkingstiff.com/images/matt.jpg" />
<div id="lens" ></div>
<div>
<script>
/* by: thinkingstiff.com
license: http://creativecommons.org/licenses/by-nc-sa/3.0/us/ */
var _gaq = _gaq || [];
_gaq.push(['_setAccount', 'UA-23915674-6']);
_gaq.push(['_trackPageview']);
(function() {
var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;
ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';
var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);
})();
var headerUri =...
CSS
#image-frame {
position: relative;
}
#lens {
background-repeat: no-repeat;
border-radius: 150px;
height: 150px;
position: absolute;
width: 150px;
}
JavaScript
document.getElementById( 'image-frame' ).addEventListener( 'mousemove', function ( event ) {
var lens = document.getElementById( 'lens' ),
image = document.getElementById( 'image' ),
radius = lens.clientWidth / 2,
imageTop = this.documentOffsetTop,
imageLeft = this.documentOffsetLeft,
zoom = 4,
lensX = ( event.pageX - radius - imageLeft ) + 'px',
lensY = ( event.pageY - radius - imageTop ) + 'px',
zoomWidth = ( image.clientWidth * zoom ) + 'px',
zoomHeight = ( image.clientHeight * zoom ) + 'px',
zoomX = -( ( ( event.pageX - imageLeft ) * zoom ) - radius ) + 'px',
zoomY = -( ( ( event.pageY - imageTop ) * zoom ) - radius ) + 'px';
if( event.pageX > imageLeft + image.clientWidth
|| event.pageX < imageLeft
|| event.pageY > imageTop + image.clientHeight
|| event.pageY < imageTop ) {
lens.style.display = 'none';
} else {
lens.style.left = lensX;
lens.style.top = lensY;
lens.style.backgroundImage = 'url(' + image.src + ')';
lens.style.backgroundSize = zoomWidth + ' ' + zoomHeight;
lens.style.backgroundPosition = zoomX + ' ' + zoomY;
lens.style.display = 'block';
};
}, false );
window.Object.defineProperty( Element.prototype, 'documentOffsetTop', {
get: function () {
return this.offsetTop + ( this.offsetParent ? this.offsetParent.documentOffsetTop : 0 );
}
} );
window.Object.defineProperty( Element.prototype, 'documentOffsetLeft', {
get: function () {
return this.offsetLeft + ( this.offsetParent ? this.offsetParent.documentOffsetLeft : 0 );
}
} );