1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51
|
function Zoom(img,finalRatio){
this.image = img;
this.ratio = finalRatio;
this.origWidth;
this.origHeight;
this.finalWidth;
this.finalHeight;
this.zoomInInt;
this.zoomOutInt;
var _this = this;
this.image.onload = function(){
this.style.cursor = "pointer";
_this.origWidth = this.width;
_this.origHeight = this.height;
_this.finalWidth = _this.origWidth / _this.ratio;
_this.finalHeight = _this.origHeight / _this.ratio;
this.width = _this.finalWidth;
this.height = _this.finalHeight;
}
this.image.onmouseover = function(){
_this.zoomInInt = window.setInterval(function(){_this.zoomIn();},30);
}
this.image.onmouseout = function(){
_this.zoomOutInt = window.setInterval(function(){_this.zoomOut();},30);
}
}
Zoom.prototype.zoomIn = function(){
clearInterval(this.zoomOutInt);
var distW = this.origWidth - this.image.width;
var distH = this.origHeight - this.image.height;
this.image.width += distW / 2;
this.image.height += distH / 2;
if(distW <= 10){
this.image.width = this.origWidth;
this.image.height = this.origHeight;
clearInterval(this.zoomInInt);
}
}
Zoom.prototype.zoomOut = function(){
clearInterval(this.zoomInInt);
var distW = this.image.width - this.finalWidth;
var distH = this.image.height - this.finalHeight;
this.image.width -= distW / 2;
this.image.height -= distH / 2;
if(distW <= 10){
this.image.width = this.finalWidth;
this.image.height = this.finalHeight;
clearInterval(this.zoomOutInt);
}
} |
Partager