⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 thumbnailpicker.js

📁 这是一个ajax的例子大家好好的看看就是一个鱼眼的效果
💻 JS
📖 第 1 页 / 共 2 页
字号:
		var scrollAttr = this.isHorizontal ? "scrollLeft" : "scrollTop";		var offset = img[pos] - this.thumbsNode[pos];		return (offset >= this.thumbScroller[scrollAttr]			&& offset + img[size] <= this.thumbScroller[scrollAttr] + this._scrollerSize);		},		_next: function() {		// summary: Displays the next page of images		var pos = this.isHorizontal ? "offsetLeft" : "offsetTop";		var size = this.isHorizontal ? "offsetWidth" : "offsetHeight";		var baseOffset = this.thumbsNode[pos];		var firstThumb = this._thumbs[this._thumbIndex];		var origOffset = firstThumb[pos] - baseOffset;			var index = -1, img;			for(var i = this._thumbIndex + 1; i < this._thumbs.length; i++){			img = this._thumbs[i];			if(img[pos] - baseOffset + img[size] - origOffset > this._scrollerSize){				this._showThumbs(i);				return;			}		}	},	_prev: function(){		// summary: Displays the next page of images		if(this.thumbScroller[this.isHorizontal ? "scrollLeft" : "scrollTop"] == 0){return;}		var pos = this.isHorizontal ? "offsetLeft" : "offsetTop";		var size = this.isHorizontal ? "offsetWidth" : "offsetHeight";			var firstThumb = this._thumbs[this._thumbIndex];		var origOffset = firstThumb[pos] - this.thumbsNode[pos];			var index = -1, img;			for(var i = this._thumbIndex - 1; i > -1; i--) {			img = this._thumbs[i];			if(origOffset - img[pos] > this._scrollerSize){				this._showThumbs(i + 1);				return;			}		}		this._showThumbs(0);	},	_checkLoad: function(img, index){		dojo.publish(this.getShowTopicName(), [{index:index}]);		this._updateNavControls();		this._loadingImages = {};			this._thumbIndex = index;			//If we have not already requested the data from the store, do so. 		if(this.thumbsNode.offsetWidth - img.offsetLeft < (this._scrollerSize * 2)){			this._loadNextPage();		}	},	_showThumbs: function(index){		// summary: Displays thumbnail images, starting at position 'index'		// index: Number		//	The index of the first thumbnail//FIXME: When is this be called with an invalid index?  Do we need this check at all?//		if(typeof index != "number"){ index = this._thumbIndex; }		index = Math.min(Math.max(index, 0), this._maxPhotos);				if(index >= this._maxPhotos){ return; }				var img = this._thumbs[index];		if(!img){ return; }				var left = img.offsetLeft - this.thumbsNode.offsetLeft;		var top = img.offsetTop - this.thumbsNode.offsetTop;		var offset = this.isHorizontal ? left : top;						if(	(offset >= this.thumbScroller[this._scrollAttr]) &&			(offset + img[this._sizeAttr] <= this.thumbScroller[this._scrollAttr] + this._scrollerSize)		){			// FIXME: WTF is this checking for?			return;		}						if(this.isScrollable){			var target = this.isHorizontal ? {x: left, y: 0} : { x:0, y:top};			dojox.fx.smoothScroll({				target: target,				win: this.thumbScroller,				duration:300,				easing:dojox.fx.easing.easeOut,				onEnd: dojo.hitch(this, "_checkLoad", img, index)			}).play(10);		}else{			if(this.isHorizontal){				this.thumbScroller.scrollLeft = left;			}else{				this.thumbScroller.scrollTop = top;			}			this._checkLoad(img, index);		}		},		markImageLoaded: function(index){		// summary: Changes a visual cue to show the image is loaded		// description: If 'useLoadNotifier' is set to true, then a visual cue is		//	given to state whether the image is loaded or not.	Calling this function		//	marks an image as loaded.		var thumbNotifier = dojo.byId("loadingDiv_"+this.widgetid+"_"+index);		if(thumbNotifier){this._setThumbClass(thumbNotifier, "thumbLoaded");}		this._loadedImages[index] = true;	},	_setThumbClass: function(thumb, className){		// summary: Adds a CSS class to a thumbnail, only if 'autoLoad' is true		// thumb: DomNode		//	The thumbnail DOM node to set the class on		// className: String		//	The CSS class to add to the DOM node.		if(!this.autoLoad){ return; }		dojo.addClass(thumb, className);	},                                                 	_loadNextPage: function(){		// summary: Loads the next page of thumbnail images		if(this._loadInProgress){return;}		this._loadInProgress = true;		var start = this.request.start + (this._noImages ? 0 : this.pageSize);				var pos = start;		while(pos < this._thumbs.length && this._thumbs[pos]){pos ++;}						//Define the function to call when the items have been 		//returned from the data store.		var complete = function(items, request){			if(items && items.length){				var itemCounter = 0;				var loadNext = dojo.hitch(this, function(){					if(itemCounter >= items.length){						this._loadInProgress = false;						return;					}					var counter = itemCounter++;					this._loadImage(items[counter], pos + counter, loadNext);				});				loadNext();				//Show or hide the navigation arrows on the thumbnails, 				//depending on whether or not the widget is at the start,				//end, or middle of the list of images. 				this._updateNavControls();			}else{				this._loadInProgress = false;			}		};			//Define the function to call if the store reports an error. 		var error = function(){			this._loadInProgress = false;			console.debug("Error getting items");		};		this.request.onComplete = dojo.hitch(this, complete);		this.request.onError = dojo.hitch(this, error);			//Increment the start parameter. This is the dojo.data API's		//version of paging. 		this.request.start = start;		this._noImages = false;				//Execute the request for data. 		this.imageStore.fetch(this.request);		},	_loadImage: function(data, index, callback){			var url = this.imageStore.getValue(data,this.imageThumbAttr);		var img = document.createElement("img");		var imgContainer = document.createElement("div");		imgContainer.setAttribute("id","img_" + this.widgetid+"_"+index);		imgContainer.appendChild(img);		img._index = index;		img._data = data;			this._thumbs[index] = imgContainer;		var loadingDiv;		if(this.useLoadNotifier){			loadingDiv = document.createElement("div");			loadingDiv.setAttribute("id","loadingDiv_" + this.widgetid+"_"+index);				//If this widget was previously told that the main image for this			//thumb has been loaded, make the loading indicator transparent.			this._setThumbClass(loadingDiv,				this._loadedImages[index] ? "thumbLoaded":"thumbNotifier");				imgContainer.appendChild(loadingDiv);		}		var size = dojo.marginBox(this.thumbsNode);		var defaultSize;		var sizeParam;		if(this.isHorizontal){			defaultSize = this.thumbWidth;			sizeParam = 'w';		} else{			defaultSize = this.thumbHeight;			sizeParam = 'h';		}		size = size[sizeParam];		var sl = this.thumbScroller.scrollLeft, st = this.thumbScroller.scrollTop;		dojo.style(this.thumbsNode, this._sizeProperty, (size + defaultSize + 20) + "px");		//Remember the scroll values, as changing the size can alter them		this.thumbScroller.scrollLeft = sl;		this.thumbScroller.scrollTop = st;		this.thumbsNode.appendChild(imgContainer);			dojo.connect(img, "onload", this, function(){			var realSize = dojo.marginBox(img)[sizeParam];			this._totalSize += (Number(realSize) + 4);			dojo.style(this.thumbsNode, this._sizeProperty, this._totalSize + "px");				if(this.useLoadNotifier){dojo.style(loadingDiv, "width", (img.width - 4) + "px"); }			callback();			return false;		});			dojo.connect(img, "onclick", this, function(evt){			dojo.publish(this.getClickTopicName(),	[{				index: evt.target._index,				data: evt.target._data,				url: img.getAttribute("src"), 				largeUrl: this.imageStore.getValue(data,this.imageLargeAttr),				title: this.imageStore.getValue(data,this.titleAttr),				link: this.imageStore.getValue(data,this.linkAttr)			}]);			return false;		});		dojo.addClass(img, "imageGalleryThumb");		img.setAttribute("src", url);		var title = this.imageStore.getValue(data, this.titleAttr);		if(title){ img.setAttribute("title",title); }		this._updateNavControls();		},	_updateNavControls: function(){		// summary: Updates the navigation controls to hide/show them when at		//	the first or last images.		var cells = [];		var change = function(node, add){			var fn = add ? "addClass" : "removeClass";			dojo[fn](node,"enabled");			dojo[fn](node,"thumbClickable");		};				var pos = this.isHorizontal ? "scrollLeft" : "scrollTop";		var size = this.isHorizontal ? "offsetWidth" : "offsetHeight";		change(this.navPrev, (this.thumbScroller[pos] > 0));				var last = this._thumbs[this._thumbs.length - 1];		var addClass = (this.thumbScroller[pos] + this._scrollerSize < this.thumbsNode[size]);		change(this.navNext, addClass);	}});}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -