ImageZoom._MODE = {
//Follow
"follow": {
methods: {
init: function() {
this._stylesFollow = null;/ /バックアップ スタイル
this._repairFollowLeft = 0;//左の補正座標
this._repairFollowTop = 0;//上側の補正座標
},
load: function() {
var viewer = this._viewer、style = viewer.style、styles;
this._stylesFollow = {
left: style.left、top: style.top、position: style.position
}; .style.position = "absolute";
//補正パラメータを取得します
if ( !viewer.offsetWidth ) {//Hide
styles = { display: style.display, Visibility: style.visibility } ;
$$D.setStyle(viewer, { display: "block", Visibility: "hidden" });
}
//中心位置を修正
this._repairFollowLeft = viewer.offsetWidth / 2 ;
this._repairFollowTop = viewer.offsetHeight / 2;
//オフセット親の位置を修正します
if ( !/BODY|HTML/.test( viewer.offsetParent.nodeName ) ) {
var parent = viewer.offsetParent、rect = $$D.rect(parent );
this._repairFollowLeft = rect.leftparent.clientLeft;
this._repairFollowTop = rect.topparent.clientTop; 🎜> if (styles) { $$D.setStyle(viewer,styles); }
},
repair: function(e, pos) {
varzoom = this._zoom,
viewerWidth = this ._viewerWidth,
viewerHeight = this._viewerHeight;
pos.left = ( viewerWidth / 2 - pos.left ) * ( viewerWidth /zoom.width - 1 ); / 2 - pos.top ) * ( viewerHeight /zoom.height - 1 );
},
move: function(e) {
var style = this._viewer.style; left = e.pageX - this._repairFollowLeft "px";
style.top = e.pageY - this._repairFollowTop "px"
},
dispose: function() {
$$ D. setStyle( this._viewer, this._stylesFollow );
}
}
},
//ドラッグ ハンドル
"handle": {
options: {//デフォルトvalue
handle: ""//ドラッグ ハンドル オブジェクト
},
methods: {
init: function() {
var handle = $$( this.options.handle ); 🎜> if ( !handle ) {//定義されていない場合は、表示ボックスをコピーで置き換えます
var body = document.body;
handle = body.insertBefore(this._viewer.cloneNode(false), body) .childNodes[0] ; 0, margin: 0, display: "none" } );
this._handle = handle;
this._repairHandleLeft = 0;//左の座標._repairHandleTop = 0;/ /修正トップ
},
load: function() {
var handle = this._handle, rect = this._rect;
$$D.setStyle( handle, {
位置 : "絶対"、
幅: this._rangeWidth "px"、
高さ: this._rangeHeight "px"、
表示: "ブロック"、
可視性: "非表示"
} );
//補正パラメータを取得します
this._repairHandleLeft = rect.left this._repairLeft - handle.clientLeft;
this._repairHandleTop = rect.top this._repairTop - handle. clientTop;
/ /オフセット親の位置を修正します
if ( !/BODY|HTML/.test( handle.offsetParent.nodeName ) ) {
varparent = handle.offsetParent, rect = $$D.rect(親);
this._repairHandleLeft -= rect.leftparent.clientLeft;
this._repairHandleTop -= rect.topparent.clientTop;
//Hide
$$D. setStyle( handle, { 表示 : "なし"、可視性: "表示" });
},
start: function() {
this._handle.style.display = "ブロック"; >},
move: function(e, x, y) {
var style = this._handle.style,scale = this._scale;
style.left = Math.ceil( this._repairHandleLeft - x / スケール ) "px ";
style.top = Math.ceil(this._repairHandleTop - y / スケール ) "px";
},
end: function() {
this. _handle.style.display = "none";
},
dispose: function() {
if( "_createbyhandle" in this._handle ){ document.body.removeChild( this._handle );
this._handle = null;
}
}
},
//Cut
"cropper": {
options: {//デフォルト値
不透明度: .5//透明性
},
メソッド: {
init: function() {
var body = document.body,
cropper = body.insertBefore(document.createElement(" img"), body.childNodes[0]);
cropper.style.display = "none";
this._cropper = Cropper;
this.opacity = this.options.opacity;
}、
load: function() {
var Cropper = this._cropper、image = this._image、rect = this._rect;
cropper.src = image.src;クロッパー.幅 = 画像.幅;
クロッパー.高さ = 画像.高さ;
位置: "絶対",
左: これ。 _repairLeft "px",
top: rect.top this._repairTop "px"
});
},
start: function() {
this._cropper.style.display = "ブロック";
$$D.setStyle(this._image, "opacity", this.opacity );
move: function(e, x, y) {
var w = this._rangeWidth, h = this._rangeHeight, スケール = this._scale;
x = Math.ceil( -x / スケール ) y = Math.ceil( -y / スケール ); .style.clip = "rect(" y "px " (x w) "px " (y h) "px " x "px)";,
end: function() {
$$D.setStyle( this._image, "opacity", 1 );
this._cropper.style.display = "なし";
},
dispose: function() {
document.body.removeChild( this._cropper );
this._cropper = null;
}
}
}
}
ImageZoom.prototype._initialize = (function(){
var init = ImageZoom.prototype._initialize,
mode = ImageZoom._MODE,
modes = {
"follow": [ mode.follow ],
"handle": [ mode.handle ],
"cropper": [ mode.cropper ],
"handle-cropper": [mode.handle, mode.cropper ]
};
return function(){
var options = argument[2];
if ( options && options. mode && modes[ options.mode ] ) {
$$A.forEach( modes[ options.mode ], function( mode ){
//扩展options
$$.extend( options, mode. options, false );
//扩展钩子
$$A.forEach(mode.methods, function(method, name ){
$$CE.addEvent(this, name, method );
}, this );
}, this );
init.apply( this, argument )
}
});地址
http://demo.jb51.net/js/ImageZoom_ext/ImageZoom_ext.htm
打包下ダウンロード地址http://www.jb51.net/jiaoben/25809.html
出处:http://www.cnblogs.com/cloudgamer/