JSFiddle - React, Tailwind, and code Playground
HTML
<div style="width:100%; height:100%;">
<div id="magnifiedImage" style="float:left; margin:20px; width:200px; height: 300px;"> </div>
<div id="magnifiedImage2" style="float:left; margin:20px; width:200px; height: 300px;"> </div>
</div>
JavaScript
var Magnifier = function(elem) {
var self = this;
var imageUrl = "http://placehold.it/400x600";
// Configure Parent Member Fields
//----------------------------------------------
// Setup the layout
elem.magnifierContainer = $("<div>").css({
"position" : "relative",
"cursor" : "none"
});
elem.magnifier = $("<div>").css({
"position" : "absolute",
"height" : "11em",
"width" : "11em",
"border-radius" : "50%",
"box-shadow" : "3px 3px 5px #111",
"background" : 'url(' + imageUrl + ') no-repeat',
"display" : "none"
});
elem.smallImage = $("<img>").attr({
"src" : imageUrl
}).css({
"width" : "100%",
"height" : "100%",
"max-width" : "400px",
"max-height" : "600px",
});
$(elem.magnifierContainer).append(elem.smallImage, elem.magnifier);
$(elem).append(elem.magnifierContainer);
// Magnifier
// ----------------------------------
this.elemparent = elem;
this.syncedMagnifier = null;
// Synchronizes this Magnifier with another (propagating all actions to aMagnifier)
this.syncWith = function(aMagnifier) {
if (!(aMagnifier instanceof Magnifier)) {
return;
}
this.syncedMagnifier = aMagnifier;
aMagnifier.syncedMagnifier = this;
};
// Sets the position of the magnifier relative to the parent
this.setPosition = function(x, y) {
// Get native image resolution
var nativeImage = new Image();
nativeImage.src = $(elem.smallImage).attr("src");
var nativeWidth = nativeImage.width;
var nativeHeight = nativeImage.height;
console.log(nativeImage.width);
//alert(nativeImage.src + ": " + nativeWidth + " / " + nativeHeight);
//...