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

📄 fancyzoom.js

📁 网页上点击浏览图片时在当前页放大图片
💻 JS
📖 第 1 页 / 共 2 页
字号:
		// Do It!		zoomTimer[theID] = setInterval("zoomElement('"+zoomID+"', '"+theID+"', "+zoomCurrent+", "+startW+", "+zoomChangeW+", "+startH+", "+zoomChangeH+", "+startX+", "+zoomChangeX+", "+startY+", "+zoomChangeY+", "+tempSteps+", "+includeFade+", "+fadeAmount+", 'zoomDone(zoomID, theID)')", zoomTime);			zoomActive[theID] = true;	}}// Finished Zooming Infunction zoomDoneIn(zoomdiv, theID) {	// Note that it's open  	zoomOpen = true;	zoomdiv = document.getElementById(zoomdiv);	// Position the table shadow behind the zoomed in image, and display it	if (document.getElementById("ShadowBox")) {		setOpacity(0, "ShadowBox");		shadowdiv = document.getElementById("ShadowBox");		shadowLeft = parseInt(zoomdiv.style.left) - 13;		shadowTop = parseInt(zoomdiv.style.top) - 8;		shadowWidth = zoomdiv.offsetWidth + 26;		shadowHeight = zoomdiv.offsetHeight + 26; 			shadowdiv.style.width = shadowWidth + 'px';		shadowdiv.style.height = shadowHeight + 'px';		shadowdiv.style.left = shadowLeft + 'px';		shadowdiv.style.top = shadowTop + 'px';		document.getElementById("ShadowBox").style.visibility = "visible";		fadeElementSetup("ShadowBox", 0, 100, 5);			} else if (! browserIsIE) {		// Or, do a fade of the modern shadow		fadeElementSetup("ZoomImage", 0, .8, 5, 0, "shadow");	}		// Position and display the CAPTION, if existing  	if (includeCaption && document.getElementById(zoomCaption).innerHTML != "") {		// setOpacity(0, zoomCaptionDiv);		zoomcapd = document.getElementById(zoomCaptionDiv);		zoomcapd.style.top = parseInt(zoomdiv.style.top) + (zoomdiv.offsetHeight + 15) + 'px';		zoomcapd.style.left = (myWidth / 2) - (zoomcapd.offsetWidth / 2) + 'px';		zoomcapd.style.visibility = "visible";		// fadeElementSetup(zoomCaptionDiv, 0, 100, 5);	}   		// Display Close Box (fade it if it's not IE)	if (!browserIsIE) setOpacity(0, "ZoomClose");	document.getElementById("ZoomClose").style.visibility = "visible";	if (!browserIsIE) fadeElementSetup("ZoomClose", 0, 100, 5);	// Get keypresses	document.onkeypress = getKey;	}// Finished Zooming Outfunction zoomDone(zoomdiv, theID) {	// No longer open  	zoomOpen = false;	// Clear stuff out, clean up	zoomOrigH[theID] = "";	zoomOrigW[theID] = "";	document.getElementById(zoomdiv).style.visibility = "hidden";	zoomActive[theID] == false;	// Stop getting keypresses	document.onkeypress = null;}// Actually zoom the elementfunction zoomElement(zoomdiv, theID, zoomCurrent, zoomStartW, zoomChangeW, zoomStartH, zoomChangeH, zoomStartX, zoomChangeX, zoomStartY, zoomChangeY, zoomSteps, includeFade, fadeAmount, execWhenDone) {	// console.log("Zooming Step #"+zoomCurrent+ " of "+zoomSteps+" (zoom " + zoomStartW + "/" + zoomChangeW + ") (zoom " + zoomStartH + "/" + zoomChangeH + ")  (zoom " + zoomStartX + "/" + zoomChangeX + ")  (zoom " + zoomStartY + "/" + zoomChangeY + ") Fade: "+fadeAmount);    	// Test if we're done, or if we continue	if (zoomCurrent == (zoomSteps + 1)) {		zoomActive[theID] = false;		clearInterval(zoomTimer[theID]);		if (execWhenDone != "") {			eval(execWhenDone);		}	} else {			// Do the Fade!	  		if (includeFade == 1) {			if (fadeAmount < 0) {				setOpacity(Math.abs(zoomCurrent * fadeAmount), zoomdiv);			} else {				setOpacity(100 - (zoomCurrent * fadeAmount), zoomdiv);			}		}	  		// Calculate this step's difference, and move it!				moveW = cubicInOut(zoomCurrent, zoomStartW, zoomChangeW, zoomSteps);		moveH = cubicInOut(zoomCurrent, zoomStartH, zoomChangeH, zoomSteps);		moveX = cubicInOut(zoomCurrent, zoomStartX, zoomChangeX, zoomSteps);		moveY = cubicInOut(zoomCurrent, zoomStartY, zoomChangeY, zoomSteps);			document.getElementById(zoomdiv).style.left = moveX + 'px';		document.getElementById(zoomdiv).style.top = moveY + 'px';		zoomimg.style.width = moveW + 'px';		zoomimg.style.height = moveH + 'px';			zoomCurrent++;				clearInterval(zoomTimer[theID]);		zoomTimer[theID] = setInterval("zoomElement('"+zoomdiv+"', '"+theID+"', "+zoomCurrent+", "+zoomStartW+", "+zoomChangeW+", "+zoomStartH+", "+zoomChangeH+", "+zoomStartX+", "+zoomChangeX+", "+zoomStartY+", "+zoomChangeY+", "+zoomSteps+", "+includeFade+", "+fadeAmount+", '"+execWhenDone+"')", zoomTime);	}}// Zoom Utility: Get Key Press when image is open, and act accordinglyfunction getKey(evt) {	if (! evt) {		theKey = event.keyCode;	} else {		theKey = evt.keyCode;	}	if (theKey == 27) { // ESC		zoomOut(this, evt);	}}//////////////////////////////// FADE Functions//function fadeOut(elem) {	if (elem.id) {		fadeElementSetup(elem.id, 100, 0, 10);	}}function fadeIn(elem) {	if (elem.id) {		fadeElementSetup(elem.id, 0, 100, 10);		}}// Fade: Initialize the fade functionvar fadeActive = new Array();var fadeQueue  = new Array();var fadeTimer  = new Array();var fadeClose  = new Array();var fadeMode   = new Array();function fadeElementSetup(theID, fdStart, fdEnd, fdSteps, fdClose, fdMode) {	// alert("Fading: "+theID+" Steps: "+fdSteps+" Mode: "+fdMode);	if (fadeActive[theID] == true) {		// Already animating, queue up this command		fadeQueue[theID] = new Array(theID, fdStart, fdEnd, fdSteps);	} else {		fadeSteps = fdSteps;		fadeCurrent = 0;		fadeAmount = (fdStart - fdEnd) / fadeSteps;		fadeTimer[theID] = setInterval("fadeElement('"+theID+"', '"+fadeCurrent+"', '"+fadeAmount+"', '"+fadeSteps+"')", 15);		fadeActive[theID] = true;		fadeMode[theID] = fdMode;				if (fdClose == 1) {			fadeClose[theID] = true;		} else {			fadeClose[theID] = false;		}	}}// Fade: Do the fade. This function will call itself, modifying the parameters, so// many instances can run concurrently. Can fade using opacity, or fade using a box-shadow.function fadeElement(theID, fadeCurrent, fadeAmount, fadeSteps) {	if (fadeCurrent == fadeSteps) {		// We're done, so clear.		clearInterval(fadeTimer[theID]);		fadeActive[theID] = false;		fadeTimer[theID] = false;		// Should we close it once the fade is complete?		if (fadeClose[theID] == true) {			document.getElementById(theID).style.visibility = "hidden";		}		// Hang on.. did a command queue while we were working? If so, make it happen now		if (fadeQueue[theID] && fadeQueue[theID] != false) {			fadeElementSetup(fadeQueue[theID][0], fadeQueue[theID][1], fadeQueue[theID][2], fadeQueue[theID][3]);			fadeQueue[theID] = false;		}	} else {		fadeCurrent++;				// Now actually do the fade adjustment.				if (fadeMode[theID] == "shadow") {			// Do a special fade on the webkit-box-shadow of the object					if (fadeAmount < 0) {				document.getElementById(theID).style.webkitBoxShadow = shadowSettings + (Math.abs(fadeCurrent * fadeAmount)) + ')';			} else {				document.getElementById(theID).style.webkitBoxShadow = shadowSettings + (100 - (fadeCurrent * fadeAmount)) + ')';			}					} else {					// Set the opacity depending on if we're adding or subtracting (pos or neg)						if (fadeAmount < 0) {				setOpacity(Math.abs(fadeCurrent * fadeAmount), theID);			} else {				setOpacity(100 - (fadeCurrent * fadeAmount), theID);			}		}		// Keep going, and send myself the updated variables		clearInterval(fadeTimer[theID]);		fadeTimer[theID] = setInterval("fadeElement('"+theID+"', '"+fadeCurrent+"', '"+fadeAmount+"', '"+fadeSteps+"')", 15);	}}//////////////////////////////// UTILITY functions//// Utility: Set the opacity, compatible with a number of browsers. Value from 0 to 100.function setOpacity(opacity, theID) {	var object = document.getElementById(theID).style;	// If it's 100, set it to 99 for Firefox.	if (navigator.userAgent.indexOf("Firefox") != -1) {		if (opacity == 100) { opacity = 99.9999; } // This is majorly awkward	}	// Multi-browser opacity setting	object.filter = "alpha(opacity=" + opacity + ")"; // IE/Win	object.opacity = (opacity / 100);                 // Safari 1.2, Firefox+Mozilla}// Utility: Math functions for animation calucations - From http://www.robertpenner.com/easing///// t = time, b = begin, c = change, d = duration// time = current frame, begin is fixed, change is basically finish - begin, duration is fixed (frames),function linear(t, b, c, d){	return c*t/d + b;}function sineInOut(t, b, c, d){	return -c/2 * (Math.cos(Math.PI*t/d) - 1) + b;}function cubicIn(t, b, c, d) {	return c*(t/=d)*t*t + b;}function cubicOut(t, b, c, d) {	return c*((t=t/d-1)*t*t + 1) + b;}function cubicInOut(t, b, c, d){	if ((t/=d/2) < 1) return c/2*t*t*t + b;	return c/2*((t-=2)*t*t + 2) + b;}function bounceOut(t, b, c, d){	if ((t/=d) < (1/2.75)){		return c*(7.5625*t*t) + b;	} else if (t < (2/2.75)){		return c*(7.5625*(t-=(1.5/2.75))*t + .75) + b;	} else if (t < (2.5/2.75)){		return c*(7.5625*(t-=(2.25/2.75))*t + .9375) + b;	} else {		return c*(7.5625*(t-=(2.625/2.75))*t + .984375) + b;	}}// Utility: Get the size of the window, and set myWidth and myHeight// Credit to quirksmode.orgfunction getSize() {	// Window Size	if (self.innerHeight) { // Everyone but IE		myWidth = window.innerWidth;		myHeight = window.innerHeight;		myScroll = window.pageYOffset;	} else if (document.documentElement && document.documentElement.clientHeight) { // IE6 Strict		myWidth = document.documentElement.clientWidth;		myHeight = document.documentElement.clientHeight;		myScroll = document.documentElement.scrollTop;	} else if (document.body) { // Other IE, such as IE7		myWidth = document.body.clientWidth;		myHeight = document.body.clientHeight;		myScroll = document.body.scrollTop;	}	// Page size w/offscreen areas	if (window.innerHeight && window.scrollMaxY) {			myScrollWidth = document.body.scrollWidth;		myScrollHeight = window.innerHeight + window.scrollMaxY;	} else if (document.body.scrollHeight > document.body.offsetHeight) { // All but Explorer Mac		myScrollWidth = document.body.scrollWidth;		myScrollHeight = document.body.scrollHeight;	} else { // Explorer Mac...would also work in Explorer 6 Strict, Mozilla and Safari		myScrollWidth = document.body.offsetWidth;		myScrollHeight = document.body.offsetHeight;	}}// Utility: Get Shift Key Status// IE events don't seem to get passed through the function, so grab it from the window.function getShift(evt) {	var shift = false;	if (! evt && window.event) {		shift = window.event.shiftKey;	} else if (evt) {		shift = evt.shiftKey;		if (shift) evt.stopPropagation(); // Prevents Firefox from doing shifty things	}	return shift;}// Utility: Find the Y position of an element on a page. Return Y and X as an arrayfunction findElementPos(elemFind){	var elemX = 0;	var elemY = 0;	do {		elemX += elemFind.offsetLeft;		elemY += elemFind.offsetTop;	} while ( elemFind = elemFind.offsetParent )	return Array(elemX, elemY);}

⌨️ 快捷键说明

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