`

html 放大镜

 
阅读更多
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> 

<html xmlns="http://www.w3.org/1999/xhtml"> 
    <head> 
        <title>wujinjian </title> 
        <base href="http://dl.iteye.com/upload/picture/pic/107118/"> 
        <script type="text/javascript"> 

            /* 
            *特别注意: 
            *放大的倍数=原图的大小/小图片显示的大小 
            *自己查看原图片的大小,我这是 400*400 px 
            */ 

            //图片对象 
            var imgObj; 
            //放大镜div对象 
            var zoomDivObj; 
            //显示小图片的div 
            var mainDivObj; 
            //放大后显示图片的div 
            var showDivObj; 
            //放大镜的大小 
            var zoomSize=50; 
            //放大镜的倍数(不能随便填) 
            var zoomMultiple=2; 
            //图片的路径 
            var imgPath="f75ff49c-34c5-3e42-a4c5-81e1832b2c74.gif"; 
            //小图片显示的大小 
            var imgW=200; 
            var imgH=200; 
            //显示的位置 
            var left=100; 
            var top=10; 
            //放大镜div的透明度(0~100) 
            var opacity=50; 
            //放大镜div的颜色 
            var rgb="223,223,223"; 

            function load() 
            { 
                if(zoomDivObj==null) 
                    createZoomDivObj(); 
                if(mainDivObj==null) 
                    createMainDivObj(); 
                if(showDivObj==null) 
                    createShowDivObj(); 
                if(imgObj==null) 
                    createImgObj(); 

                zoomDivObj.style.width=zoomSize+"px"; 
                zoomDivObj.style.height=zoomSize+"px"; 

                showDivObj.style.width=zoomSize*zoomMultiple+"px"; 
                showDivObj.style.height=zoomSize*zoomMultiple+"px"; 

                showDivObj.style.backgroundImage="url("+imgPath+")"; 

                imgObj.src=imgPath; 
                imgObj.style.width=imgW+"px"; 
                imgObj.style.height=imgH+"px"; 

                mainDivObj.style.width=imgW+"px"; 
                mainDivObj.style.height=imgH+"px"; 
                mainDivObj.style.left=left+"px"; 
                mainDivObj.style.top=top+"px"; 

                showDivObj.style.left=left+imgW+50+"px"; 
                showDivObj.style.top=top+"px"; 

                zoomDivObj.style.backgroundColor="rgb("+rgb+")"; 
                
                //两个都要写,为了IE 和 火狐 的通用 
                zoomDivObj.style.filter="alpha(opacity="+opacity+")"; 
                zoomDivObj.style.opacity=opacity/100; 
            } 

            function showZoomDiv() 
            { 
                if(zoomDivObj==null) 
                    createZoomDivObj(); 

                zoomDivObj.style.visibility="visible"; 
            } 
            
            function moveZoomDiv(e) 
            { 
                if(zoomDivObj==null) 
                    createZoomDivObj(); 

                var w=zoomDivObj.style.width.replace("px","")-0; 
                var h=zoomDivObj.style.height.replace("px","")-0; 
                
                if(mainDivObj==null) 
                    createMainDivObj(); 

                var mouseX=e.clientX-(mainDivObj.style.left.replace("px","")-0); 
                var mouseY=e.clientY-(mainDivObj.style.top.replace("px","")-0); 
                
                window.status=mouseX+"    "+mouseY; 

                zoomDivObj.style.left=mouseX-(w/2)+"px"; 
                zoomDivObj.style.top=mouseY-(h/2)+"px"; 

                if(showDivObj==null) 
                    createShowDivObj(); 
                
                showDivObj.style.backgroundPosition=(-mouseX+w/2)*zoomMultiple+"px "+(-mouseY+h/2)*zoomMultiple+"px"; 
            } 

            function hiddenZoomDiv() 
            { 
                if(zoomDivObj==null) 
                    createZoomDivObj(); 

                //zoomDivObj.style.visibility="hidden"; 
            } 

            function createZoomDivObj() 
            { 
                zoomDivObj=document.getElementById("zoom_div_id"); 
            } 

            function createMainDivObj() 
            { 
                mainDivObj=document.getElementById("main_div_id"); 
            } 

            function createShowDivObj() 
            { 
                showDivObj=document.getElementById("show_div_id"); 
            } 

            function createImgObj() 
            { 
                imgObj=document.getElementById("img_id"); 
            } 
        </script> 
    </head> 
    <body onmousemove="moveZoomDiv(event)" onload="load()"> 
        <div id="main_div_id" style="position:absolute;overflow:hidden;background-color:cyan;border:gray solid 1px;" onmouseover="showZoomDiv()" onmouseout="hiddenZoomDiv()" > 
            <img id="img_id"> 

            <div id="zoom_div_id" style="position:absolute;left:0px;top:0px;overflow:hidden;visibility:hidden;"> </div> 
        </div> 

        <div id="show_div_id" style="position:absolute;overflow:hidden;background-color:cyan;background-repeat:no-repeat;border:gray solid 1px;" > </div> 
    </body> 
</html>


<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> 

<html xmlns="http://www.w3.org/1999/xhtml"> 
   <head>
<bgsound src="路径" loop="-1">/* ===== 背景音乐 ==== */
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<title>图片欣赏</title>
<style type="text/css">
	html {
		overflow: hidden;
	}

	body {
		margin: 0px;
		padding: 0px;
		background: #000;
		position: absolute;
		width: 100%;
		height: 100%;
		cursor: crosshair;
	}

	#diapoContainer {
		position: absolute;
		left: 10%;
		top: 10%;
		width: 80%;
		height: 80%;
		background: #222;
		overflow: hidden;
	}

	.imgDC {
		position: absolute;
		cursor: pointer;
		border: #000 solid 2px;
		filter: alpha(opacity=90);
		opacity: 0.9;
		visibility: hidden;
	}

	.spaDC {
		position: absolute;
		filter: alpha(opacity=20);
		opacity: 0.2;
		background: #000;
		visibility: hidden;
	}

	.imgsrc {
		position: absolute;
		width: 120px;
		height: 67px;
		visibility: hidden;
		margin: 4%;
	}

	#bkgcaption {
		position: absolute;
		bottom: 0px;
		left: 0px;
		width: 100%;
		height: 6%;
		background:#1a1a1a;
	}
	#caption {
		position: absolute;
		font-family: arial, helvetica, verdana, sans-serif;
		white-space: nowrap;
		color: #fff;
		bottom: 0px;
		width: 100%;
		left: -10000px;
		text-align: center;
	}

</style>
<script type="text/javascript">
var xm;
var ym;

/* ==== onmousemove event ==== */
document.onmousemove = function(e){
	if(window.event) e=window.event;
	xm = (e.x || e.clientX);
	ym = (e.y || e.clientY);
}

/* ==== window resize ==== */
function resize() {
	if(diapo)diapo.resize();
}
onresize = resize;

/* ==== opacity ==== */
setOpacity = function(o, alpha){
	if(o.filters)o.filters.alpha.opacity = alpha * 100; else o.style.opacity = alpha;
}


////////////////////////////////////////////////////////////////////////////////////////////
/* ===== encapsulate script ==== */
diapo = {
	O : [],
	DC : 0,
	img : 0,
	txt : 0,
	N : 0,
	xm : 0,
	ym : 0,
	nx : 0,
	ny : 0,
	nw : 0,
	nh : 0,
	rs : 0,
	rsB : 0,
	zo : 0,
	tx_pos : 0,
	tx_var : 0,
	tx_target : 0,

	/////// script parameters ////////
	attraction : 2,
	acceleration : .9,
	dampening : .1,
	zoomOver : 2,
	zoomClick : 6,
	transparency : .8,
	font_size: 18,
	//////////////////////////////////

	/* ==== diapo resize ==== */
	resize : function(){
		with(this){
			nx = DC.offsetLeft;
			ny = DC.offsetTop;
			nw = DC.offsetWidth;
			nh = DC.offsetHeight;
			txt.style.fontSize = Math.round(nh / font_size) + "px";
			if(Math.abs(rs-rsB)<100) for(var i=0; i<N; i++) O[i].resize();
			rsB = rs;
		}
	},

	/* ==== create diapo ==== */
	CDiapo : function(o){
		/* ==== init variables ==== */
		this.o        = o;
		this.x_pos    = this.y_pos    = 0;
		this.x_origin = this.y_origin = 0;
		this.x_var    = this.y_var    = 0;
		this.x_target = this.y_target = 0;
		this.w_pos    = this.h_pos    = 0;
		this.w_origin = this.h_origin = 0;
		this.w_var    = this.h_var    = 0;
		this.w_target = this.h_target = 0;
		this.over     = false;
		this.click    = false;

		/* ==== create shadow ==== */
		this.spa = document.createElement("span");
		this.spa.className = "spaDC";
		diapo.DC.appendChild(this.spa);

		/* ==== create thumbnail image ==== */
		this.img = document.createElement("img");
		this.img.className = "imgDC";
		this.img.src = o.src;
		this.img.O = this;
		diapo.DC.appendChild(this.img);
		setOpacity(this.img, diapo.transparency);

		/* ==== mouse events ==== */
		this.img.onselectstart = new Function("return false;");
		this.img.ondrag = new Function("return false;");
		this.img.onmouseover = function(){
			diapo.tx_target=0;
			diapo.txt.innerHTML=this.O.o.alt;
			this.O.over=true;
			setOpacity(this,this.O.click?diapo.transparency:1);
		}
		this.img.onmouseout = function(){
			diapo.tx_target=-diapo.nw;
			this.O.over=false;
			setOpacity(this,diapo.transparency);
		}
		this.img.onclick = function() {
			if(!this.O.click){
				if(diapo.zo && diapo.zo != this) diapo.zo.onclick();
				this.O.click = true;
				this.O.x_origin = (diapo.nw - (this.O.w_origin * diapo.zoomClick)) / 2;
				this.O.y_origin = (diapo.nh - (this.O.h_origin * diapo.zoomClick)) / 2;
				diapo.zo = this;
				setOpacity(this,diapo.transparency);
			} else {
				this.O.click = false;
				this.O.over = false;
				this.O.resize();
				diapo.zo = 0;
			}
		}

		/* ==== rearrange thumbnails based on "imgsrc" images position ==== */
		this.resize = function (){
			with (this) {
				x_origin = o.offsetLeft;
				y_origin = o.offsetTop;
				w_origin = o.offsetWidth;
				h_origin = o.offsetHeight;
			}
		}

		/* ==== animation function ==== */
		this.position = function (){
			with (this) {
				/* ==== set target position ==== */
				w_target = w_origin;
				h_target = h_origin;
				if(over){
					/* ==== mouse over ==== */
					w_target = w_origin * diapo.zoomOver;
					h_target = h_origin * diapo.zoomOver;
					x_target = diapo.xm - w_pos / 2 - (diapo.xm - (x_origin + w_pos / 2)) / (diapo.attraction*(click?10:1));
					y_target = diapo.ym - h_pos / 2 - (diapo.ym - (y_origin + h_pos / 2)) / (diapo.attraction*(click?10:1));
				} else {
					/* ==== mouse out ==== */
					x_target = x_origin;
					y_target = y_origin;
				}
				if(click){
					/* ==== clicked ==== */
					w_target = w_origin * diapo.zoomClick;
					h_target = h_origin * diapo.zoomClick;
				}

				/* ==== magic spring equations ==== */
				x_pos += x_var = x_var * diapo.acceleration + (x_target - x_pos) * diapo.dampening;
				y_pos += y_var = y_var * diapo.acceleration + (y_target - y_pos) * diapo.dampening;
				w_pos += w_var = w_var * (diapo.acceleration * .5) + (w_target - w_pos) * (diapo.dampening * .5);
				h_pos += h_var = h_var * (diapo.acceleration * .5) + (h_target - h_pos) * (diapo.dampening * .5);
				diapo.rs += (Math.abs(x_var) + Math.abs(y_var));

				/* ==== html animation ==== */
				with(img.style){
					left   = Math.round(x_pos) + "px";
					top    = Math.round(y_pos) + "px";
					width  = Math.round(Math.max(0, w_pos)) + "px";
					height = Math.round(Math.max(0, h_pos)) + "px";
					zIndex = Math.round(w_pos);
				}
				with(spa.style){
					left   = Math.round(x_pos + w_pos * .1) + "px";
					top    = Math.round(y_pos + h_pos * .1) + "px";
					width  = Math.round(Math.max(0, w_pos * 1.1)) + "px";
					height = Math.round(Math.max(0, h_pos * 1.1)) + "px";
					zIndex = Math.round(w_pos);
				}
			}
		}
	},

	/* ==== main loop ==== */
	run : function(){
		diapo.xm = xm - diapo.nx;
		diapo.ym = ym - diapo.ny;
		/* ==== caption anim ==== */
		diapo.tx_pos += diapo.tx_var = diapo.tx_var * .9 + (diapo.tx_target - diapo.tx_pos) * .02;
		diapo.txt.style.left = Math.round(diapo.tx_pos) + "px";
		/* ==== images anim ==== */
		for(var i in diapo.O) diapo.O[i].position();
		/* ==== loop ==== */
		setTimeout("diapo.run();", 16);
	},

	/* ==== load images ==== */
	images_load : function(){
		// ===== loop until all images are loaded =====
		var M = 0;
		for(var i=0; i<diapo.N; i++) {
			if(diapo.img[i].complete) {
				diapo.img[i].style.position = "relative";
				diapo.O[i].img.style.visibility = "visible";
				diapo.O[i].spa.style.visibility = "visible";
				M++;
			}
			resize();
		}
		if(M<diapo.N) setTimeout("diapo.images_load();", 128);
	},

	/* ==== init script ==== */
	init : function() {
		diapo.DC = document.getElementById("diapoContainer");
		diapo.img = diapo.DC.getElementsByTagName("img");
		diapo.txt = document.getElementById("caption");
		diapo.N = diapo.img.length;
		for(i=0; i<15; i++) diapo.O.push(new diapo.CDiapo(diapo.img[i]));
		diapo.resize();
		diapo.tx_pos = -diapo.nw;
		diapo.tx_target = -diapo.nw;
		diapo.images_load();
		diapo.run();
	}
}
</script>
</head>
<body>
<div id="diapoContainer">
	<img class="imgsrc" src="" alt="图片的注释(第一张)">
	<img class="imgsrc" src="" alt="同上">
	<img class="imgsrc" src="" alt="同上">
	<img class="imgsrc" src="" alt="同上">
       <img class="imgsrc" src="" alt="同上">
	<img class="imgsrc" src="" alt="同上">
	<img class="imgsrc" src="" alt="同上">
	<img class="imgsrc" src="" alt="同上">
	<img class="imgsrc" src="" alt="同上">
	<img class="imgsrc" src="" alt="同上">
	<img class="imgsrc" src="" alt="同上">
	<img class="imgsrc" src="" alt="同上">
	<img class="imgsrc" src="" alt="同上">
       <img class="imgsrc" src="" alt="同上">
	<img class="imgsrc" src="" alt="同上">
        <div id="bkgcaption">
	</div>
	<div id="caption">
	</div>
</div>
<script type="text/javascript">
/* ==== start script ==== */
function dom_onload() {
	if(document.getElementById("diapoContainer")) diapo.init(); else setTimeout("dom_onload();", 128);
}
dom_onload();
</script>
</body>
</html>
分享到:
评论

相关推荐

    HTML放大镜功能,简单易用

    HTML放大镜功能是一种常见的网页交互设计,用于提升用户体验,特别是在展示细节丰富的图片时。这个功能让用户能够轻松查看图片的局部细节,而无需离开当前页面或打开新的窗口。它在电商网站、艺术画廊或者任何需要...

    jQuery html 放大镜效果

    这里我们关注的是两个实现这一效果的jQuery插件:一个是基础的html放大镜效果,另一个是名为Cloud Zoom的高级放大镜插件。 首先,我们来了解基础的html放大镜效果。这个效果通常是通过JavaScript和CSS来实现的。...

    html.rar_html放大镜案例

    HTML放大镜功能是一种常见于电商网站的产品细节展示技术,它允许用户通过鼠标悬停在图片上,局部区域会以放大效果显示,以便更清晰地查看产品的细节。这个"html.rar_html放大镜案例"是一个实现此类功能的实例。下面...

    HTML5 商品放大镜效果

    HTML5商品放大镜效果是一种常见的电商网站交互设计,它能够为用户提供更加直观的商品细节查看体验。在本案例中,我们关注的是如何利用HTML5技术来实现这种效果,特别是在"Day3_Magnifier.zip"这个压缩包中所包含的...

    放大镜功能

    通过这种方式,我们可以创建一个基本的HTML放大镜功能。实际应用中可能还需要考虑性能优化、触摸设备的支持以及不同浏览器的兼容性等问题。`macbook-big.jpg` 可能是放大的高清图片,用于在放大镜中显示更清晰的细节...

    html的放大镜效果.zip

    HTML放大镜效果是一种常见的网页交互设计,它允许用户在页面上选择一个区域并实时预览该区域的放大图像,提供了一种类似于实体放大镜的视觉体验。这种效果通常用于产品展示,尤其是那些需要用户查看细节的商品图片。...

    jfMagnify-可以放大任何HTML元素的jQuery放大镜插件

    jfMagnify是一款可以放大任何HTML元素的jQuery放大镜插件。该放大镜插件不仅可以放大图片,还可以放大任何的HTML元素,例如超链接,文本等。该放大镜插件的原理是通过克隆元素和它的子元素,并将克隆的元素进行放大...

    放大镜.html

    一个简单的放大镜的demo,功能实现,代码较少。注意图片路径,有问题可以联系。

    商城放大镜

    综上所述,【商城放大镜】是通过结合HTML、CSS和jQuery实现的一种交互式产品展示技术,JQZOOM插件则为此提供了便捷的实现方式。通过熟练掌握这些技术,开发者可以为电商网站创造出更优质的商品展示效果,提升用户的...

    放大镜(HTML)实例

    在网页设计中,实现一个HTML放大镜功能是一个常见的交互效果,它可以增强用户的浏览体验,特别是对于展示细节丰富的图像,如产品图片或者艺术作品时。这个实例是基于HTML和可能的CSS以及JavaScript技术来创建的。...

    HTML+css+JavaScript实现放大镜效果

    首先,HTML(超文本标记语言)是网页的基础结构,我们需要创建一个包含图片和放大镜容器的布局。例如: ```html &lt;div id="magnifier"&gt;&lt;/div&gt; ``` 这里的`&lt;img&gt;`标签用于展示原始图片,而`...

    简单实用jQuery图片放大镜效果

    总结,实现一个简单的jQuery图片放大镜效果主要涉及到HTML布局、CSS样式以及jQuery事件监听和DOM操作。通过这样的方法,我们可以为用户提供一种直观的方式来查看网页中图片的细节,提升用户在浏览产品或欣赏图片时的...

    js css样式放大镜

    3. **css** - Cascading Style Sheets,用于描述HTML或XML(包括如SVG、MathML等各种XML方言)文档的样式语言,这里用于实现放大镜的视觉效果。 **压缩包子文件的文件名称列表:** "js放大镜",这可能是包含...

    放大镜效果.rar

    总结,创建HTML放大镜效果主要涉及以下步骤: 1. 使用HTML构建基本结构。 2. 使用CSS进行样式布局和设计放大镜效果。 3. 使用JavaScript动态更新放大镜的放大区域,并在鼠标移动时绘制放大区域。 通过这样的方式,...

    自适图片大小的产品放大镜

    综上所述,"自适图片大小的产品放大镜"是一个结合了HTML、CSS和JavaScript技术的交互设计,它涉及到图片自适应、鼠标交互、浏览器兼容性、性能优化等多个方面,为用户提供了一个便捷的查看产品细节的方式。...

    jquery 类淘宝商品图片放大镜

    **jQuery 淘宝商品图片放大镜** 在电商网站中,商品图片的展示往往需要具有交互性和细节展示功能,以帮助消费者更好地了解产品。其中,淘宝商品图片放大镜就是一个非常典型的例子,它允许用户在不离开当前页面的...

    JQuery 类似淘宝商品放大镜效果

    在网页设计中,为了提升用户体验,特别是在展示商品细节时,"淘宝商品放大镜效果"是一种常见且实用的技术。这个效果允许用户在鼠标悬停在图片上时,能看到一个放大的部分,以便更清晰地查看商品的细节。在这个实例中...

    JS+HTML图片放大镜效果

    本文将详细讲解如何利用JavaScript(JS)和HTML实现图片放大镜效果。 首先,我们需要理解基本的HTML结构。在HTML中,我们创建一个主图片元素`&lt;img&gt;`来显示原图,以及一个浮动的放大镜视窗元素,可以是`&lt;div&gt;`,用来...

    js放大镜 html特效

    本文将详细探讨如何使用JS实现HTML中的放大镜特效。 首先,我们要理解放大镜效果的基本原理。这个效果通常由两个部分组成:一个是原始图片,另一个是放大部分。当鼠标在原始图片上移动时,放大部分会显示一个放大的...

Global site tag (gtag.js) - Google Analytics