function() {
			var self = this;
			//绑定图片 tap 事件
			document.addEventListener(enterEventName, function(event) {
				if (!self.viewer) return;
				var target = event.target;
				if (!self.checkImage(target)) return;
				self.viewer.style.display = 'block';
				setTimeout(function() {
					self.viewer.style.opacity = 1;
				}, 0);
				self.index = self.images.indexOf(target);
				self.currentItem = self.createImage(self.index);
			}, false);
			//关系按钮事件
			self.closeButton.addEventListener(tapEventName, function(event) {
				self.viewer.style.opacity = 0;
				setTimeout(function() {
					self.viewer.style.display = 'none';
					self.disposeImage(true);
				}, 600);
				event.preventDefault();
				event.cancelBubble = true;
			}, false);
			//处理左右按钮
			self.leftButton.addEventListener(tapEventName, function() {
				self.prev();
			}, false);
			self.rightButton.addEventListener(tapEventName, function() {
				self.next();
			}, false);
			//处理划动
			self.mask.addEventListener($.EVENT_MOVE, function(event) {
				event.preventDefault();
				event.cancelBubble = true;
			}, false);
			self.viewer.addEventListener('swipeleft', function(event) {
				if (self.scaleValue == 1) self.next();
				event.preventDefault();
				event.cancelBubble = true;
			}, false);
			self.viewer.addEventListener('swiperight', function(event) {
				if (self.scaleValue == 1) self.prev();
				event.preventDefault();
				event.cancelBubble = true;
			}, false);
			//处理缩放开始
			self.viewer.addEventListener($.EVENT_START, function(event) {
				var touches = event.touches;
				if (touches.length == 2) {
					var p1 = touches[0];
					var p2 = touches[1];
					var x = p1.pageX - p2.pageX; //x1-x2
					var y = p1.pageY - p2.pageY; //y1-y2
					self.scaleStart = Math.sqrt(x * x + y * y);
					self.isMultiTouch = true;
				} else if (touches.length = 1) {
					self.dragStart = touches[0];
				}
			}, false);
			self.viewer.addEventListener($.EVENT_MOVE, function(event) {
				var img = self.currentItem.querySelector('img');
				var touches = event.changedTouches;
				if (touches.length == 2) {
					event.preventDefault();
					event.cancelBubble = true;
					var p1 = touches[0];
					var p2 = touches[1];
					var x = p1.pageX - p2.pageX;
					var y = p1.pageY - p2.pageY;
					self.scaleEnd = Math.sqrt(x * x + y * y);
					self._scaleValue = (self.scaleValue * (self.scaleEnd / self.scaleStart));
					//self.state.innerText = self._scaleValue;
					img.style.webkitTransform = "scale(" + self._scaleValue + "," + self._scaleValue + ") "; // + " translate(" + self.dragX || 0 + "px," + self.dragY || 0 + "px)";
				} else if (!self.isMultiTouch && touches.length == 1 && self.scaleValue != 1) {
					event.preventDefault();
					event.cancelBubble = true;
					self.dragEnd = touches[0];
					self._dragX = self.dragX + (self.dragEnd.pageX - self.dragStart.pageX);
					self._dragY = self.dragY + (self.dragEnd.pageY - self.dragStart.pageY);
					img.style.marginLeft = self._dragX + 'px';
					img.style.marginTop = self._dragY + 'px';
					//img.style.transform = "translate(" + self._dragX + "px," + self._dragY + "px) " + " scale(" + self.scaleValue || 1 + "," + self.scaleValue || 1 + ")";
				}
			}, false);
			self.viewer.addEventListener($.EVENT_END, function() {
				self.scaleValue = self._scaleValue || self.scaleValue;
				self._scaleValue = null;
				self.dragX = self._dragX;
				self.dragY = self._dragY;
				self._dragX = null;
				self._dragY = null;
				var touches = event.touches;
				self.isMultiTouch = (touches.length != 0);
			});
			// doubletap 好像不能用
			self.viewer.addEventListener('doubletap', function() {
				var img = self.currentItem.querySelector('img');
				if (self.scaleValue === 1) {
					self.scaleValue = 2;
				} else {
					self.scaleValue = 1;
				}
				self.dragX = 0;
				self.dragY = 0;
				img.style.marginLeft = self.dragX + 'px';
				img.style.marginTop = self.dragY + 'px';
				img.style.webkitTransform = "scale(" + self.scaleValue + "," + self.scaleValue + ") "; //+ " translate(" + self.dragX || 0 + "px," + self.dragY || 0 + "px)";
				self.viewer.__tap_num = 0;
			}, false);
			//处理缩放结束
		}
function() {
			var self = this;
			//绑定图片 tap 事件
			document.addEventListener(enterEventName, function(event) {
				if (!self.viewer) return;
				var target = event.target;
				if (!self.checkImage(target)) return;
				self.viewer.style.display = 'block';
				setTimeout(function() {
					self.viewer.style.opacity = 1;
				}, 0);
				self.index = self.images.indexOf(target);
				self.currentItem = self.createImage(self.index);
			}, false);
			//关系按钮事件
			self.closeButton.addEventListener(tapEventName, function(event) {
				self.viewer.style.opacity = 0;
				setTimeout(function() {
					self.viewer.style.display = 'none';
					self.disposeImage(true);
				}, 600);
				event.preventDefault();
				event.cancelBubble = true;
			}, false);
			//处理左右按钮
			self.leftButton.addEventListener(tapEventName, function() {
				self.prev();
			}, false);
			self.rightButton.addEventListener(tapEventName, function() {
				self.next();
			}, false);
			//处理划动
			self.mask.addEventListener($.EVENT_MOVE, function(event) {
				event.preventDefault();
				event.cancelBubble = true;
			}, false);
			self.viewer.addEventListener('swipeleft', function(event) {
				if (self.scaleValue == 1) self.next();
				event.preventDefault();
				event.cancelBubble = true;
			}, false);
			self.viewer.addEventListener('swiperight', function(event) {
				if (self.scaleValue == 1) self.prev();
				event.preventDefault();
				event.cancelBubble = true;
			}, false);
			//处理缩放开始
			self.viewer.addEventListener($.EVENT_START, function(event) {
				var touches = event.touches;
				if (touches.length == 2) {
					var p1 = touches[0];
					var p2 = touches[1];
					var x = p1.pageX - p2.pageX; //x1-x2
					var y = p1.pageY - p2.pageY; //y1-y2
					self.scaleStart = Math.sqrt(x * x + y * y);
					self.isMultiTouch = true;
				} else if (touches.length = 1) {
					self.dragStart = touches[0];
				}
			}, false);
			self.viewer.addEventListener($.EVENT_MOVE, function(event) {
				var img = self.currentItem.querySelector('img');
				var touches = event.changedTouches;
				if (touches.length == 2) {
					event.preventDefault();
					event.cancelBubble = true;
					var p1 = touches[0];
					var p2 = touches[1];
					var x = p1.pageX - p2.pageX;
					var y = p1.pageY - p2.pageY;
					self.scaleEnd = Math.sqrt(x * x + y * y);
					self._scaleValue = (self.scaleValue * (self.scaleEnd / self.scaleStart));
					//self.state.innerText = self._scaleValue;
					img.style.webkitTransform = "scale(" + self._scaleValue + "," + self._scaleValue + ") "; // + " translate(" + self.dragX || 0 + "px," + self.dragY || 0 + "px)";
				} else if (!self.isMultiTouch && touches.length == 1 && self.scaleValue != 1) {
					event.preventDefault();
					event.cancelBubble = true;
					self.dragEnd = touches[0];
					self._dragX = self.dragX + (self.dragEnd.pageX - self.dragStart.pageX);
					self._dragY = self.dragY + (self.dragEnd.pageY - self.dragStart.pageY);
					img.style.marginLeft = self._dragX + 'px';
					img.style.marginTop = self._dragY + 'px';
					//img.style.transform = "translate(" + self._dragX + "px," + self._dragY + "px) " + " scale(" + self.scaleValue || 1 + "," + self.scaleValue || 1 + ")";
				}
			}, false);
			self.viewer.addEventListener($.EVENT_END, function() {
				self.scaleValue = self._scaleValue || self.scaleValue;
				self._scaleValue = null;
				self.dragX = self._dragX;
				self.dragY = self._dragY;
				self._dragX = null;
				self._dragY = null;
				var touches = event.touches;
				self.isMultiTouch = (touches.length != 0);
			});
			// doubletap 好像不能用
			self.viewer.addEventListener('doubletap', function() {
				var img = self.currentItem.querySelector('img');
				if (self.scaleValue === 1) {
					self.scaleValue = 2;
				} else {
					self.scaleValue = 1;
				}
				self.dragX = 0;
				self.dragY = 0;
				img.style.marginLeft = self.dragX + 'px';
				img.style.marginTop = self.dragY + 'px';
				img.style.webkitTransform = "scale(" + self.scaleValue + "," + self.scaleValue + ") "; //+ " translate(" + self.dragX || 0 + "px," + self.dragY || 0 + "px)";
				self.viewer.__tap_num = 0;
			}, false);
			//处理缩放结束
		}
function ( ) { var self = this ; //绑定图片 tap 事件 document . addEventListener ( enterEventName , function ( event ) { if ( ! self . viewer ) return ; var target = event . target ; if ( ! self . checkImage ( target ) ) return ; self . viewer . style . display = 'block' ; setTimeout ( function ( ) { self . viewer . style . opacity = 1 ; } , 0 ) ; self . index = self . images . indexOf ( target ) ; self . currentItem = self . createImage ( self . index ) ; } , false ) ; //关系按钮事件 self . closeButton . addEventListener ( tapEventName , function ( event ) { self . viewer . style . opacity = 0 ; setTimeout ( function ( ) { self . viewer . style . display = 'none' ; self . disposeImage ( true ) ; } , 600 ) ; event . preventDefault ( ) ; event . cancelBubble = true ; } , false ) ; //处理左右按钮 self . leftButton . addEventListener ( tapEventName , function ( ) { self . prev ( ) ; } , false ) ; self . rightButton . addEventListener ( tapEventName , function ( ) { self . next ( ) ; } , false ) ; //处理划动 self . mask . addEventListener ( $ . EVENT_MOVE , function ( event ) { event . preventDefault ( ) ; event . cancelBubble = true ; } , false ) ; self . viewer . addEventListener ( 'swipeleft' , function ( event ) { if ( self . scaleValue == 1 ) self . next ( ) ; event . preventDefault ( ) ; event . cancelBubble = true ; } , false ) ; self . viewer . addEventListener ( 'swiperight' , function ( event ) { if ( self . scaleValue == 1 ) self . prev ( ) ; event . preventDefault ( ) ; event . cancelBubble = true ; } , false ) ; //处理缩放开始 self . viewer . addEventListener ( $ . EVENT_START , function ( event ) { var touches = event . touches ; if ( touches . length == 2 ) { var p1 = touches [ 0 ] ; var p2 = touches [ 1 ] ; var x = p1 . pageX - p2 . pageX ; //x1-x2 var y = p1 . pageY - p2 . pageY ; //y1-y2 self . scaleStart = Math . sqrt ( x * x + y * y ) ; self . isMultiTouch = true ; } else if ( touches . length = 1 ) { self . dragStart = touches [ 0 ] ; } } , false ) ; self . viewer . addEventListener ( $ . EVENT_MOVE , function ( event ) { var img = self . currentItem . querySelector ( 'img' ) ; var touches = event . changedTouches ; if ( touches . length == 2 ) { event . preventDefault ( ) ; event . cancelBubble = true ; var p1 = touches [ 0 ] ; var p2 = touches [ 1 ] ; var x = p1 . pageX - p2 . pageX ; var y = p1 . pageY - p2 . pageY ; self . scaleEnd = Math . sqrt ( x * x + y * y ) ; self . _scaleValue = ( self . scaleValue * ( self . scaleEnd / self . scaleStart ) ) ; //self.state.innerText = self._scaleValue; img . style . webkitTransform = "scale(" + self . _scaleValue + "," + self . _scaleValue + ") " ; // + " translate(" + self.dragX || 0 + "px," + self.dragY || 0 + "px)"; } else if ( ! self . isMultiTouch && touches . length == 1 && self . scaleValue != 1 ) { event . preventDefault ( ) ; event . cancelBubble = true ; self . dragEnd = touches [ 0 ] ; self . _dragX = self . dragX + ( self . dragEnd . pageX - self . dragStart . pageX ) ; self . _dragY = self . dragY + ( self . dragEnd . pageY - self . dragStart . pageY ) ; img . style . marginLeft = self . _dragX + 'px' ; img . style . marginTop = self . _dragY + 'px' ; //img.style.transform = "translate(" + self._dragX + "px," + self._dragY + "px) " + " scale(" + self.scaleValue || 1 + "," + self.scaleValue || 1 + ")"; } } , false ) ; self . viewer . addEventListener ( $ . EVENT_END , function ( ) { self . scaleValue = self . _scaleValue || self . scaleValue ; self . _scaleValue = null ; self . dragX = self . _dragX ; self . dragY = self . _dragY ; self . _dragX = null ; self . _dragY = null ; var touches = event . touches ; self . isMultiTouch = ( touches . length != 0 ) ; } ) ; // doubletap 好像不能用 self . viewer . addEventListener ( 'doubletap' , function ( ) { var img = self . currentItem . querySelector ( 'img' ) ; if ( self . scaleValue === 1 ) { self . scaleValue = 2 ; } else { self . scaleValue = 1 ; } self . dragX = 0 ; self . dragY = 0 ; img . style . marginLeft = self . dragX + 'px' ; img . style . marginTop = self . dragY + 'px' ; img . style . webkitTransform = "scale(" + self . scaleValue + "," + self . scaleValue + ") " ; //+ " translate(" + self.dragX || 0 + "px," + self.dragY || 0 + "px)"; self . viewer . __tap_num = 0 ; } , false ) ; //处理缩放结束 }
绑定事件
绑定事件
Add event listeners