如题所示,我现在想让这段代码在开始显示的时候,显示图片的缩略图而不是图片的一部分,请各位大侠帮帮忙吧,我把剩下的全部积分都赠送给大家。
<!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>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<title>代码(十)</title>
<meta http-equiv="imagetoolbar" content="no">
<style type="text/css">
body {
background: #222;
overflow: hidden;
left: 0;
top: 0;
width: 100%;
height: 100%;
margin: 0;
padding: 0;
}
#screen span {
position:absolute;
overflow:hidden;
border:#FFF solid 1px;
background:#FFF;
}
#screen img{
position:absolute;
left:-32px;
top:-32px;
cursor: pointer;
}
#caption, #title{
color: #FFF;
font-family: georgia, 'times new roman', times, veronica, serif;
font-size: 1em;
text-align: center;
}
#caption b {
font-size: 2em;
}</style>
<script type="text/javascript"><!--
window.onerror = new Function("return true");
var obj = [];
var scr;
var spa;
var img;
var W;
var Wi;
var Hi;
var wi;
var hi;
var Sx;
var Sy;
var M;
var xm;
var ym;
var xb = 0;
var yb = 0;
var ob = - 1;
var cl = false;/* needed in standard mode */
px = function(x)
{
return Math.round(x) + "px";
}/* center image - do not resize for perf. reason */
img_center = function(o)
{
with(img[o])
{
style.left = px( - (width - Wi) / 2);
style.top = px( - (height - Hi) / 2);
}
}//////////////////////////////////////////////////////////
var Nx = 4; //size grid x
var Ny = 4; //size grid y
var Tx = 3; // image width
var Ty = 3; // image height
var Mg = 40; // margin
var SP = 1; // speed
//////////////////////////////////////////////////////////function Cobj(o, x, y)
{
this.o = o;
this.ix = Math.min(Nx - Tx, Math.max(0, Math.round(x - (Tx / 2))));
this.iy = Math.min(Ny - Ty, Math.max(0, Math.round(y - (Ty / 2))));
this.li = ((this.ix * M + this.ix * Sx) - (x * M + x * Sx)) / SP;
this.ti = ((this.iy * M + this.iy * Sy) - (y * M + y * Sy)) / SP;
this.l = 0;
this.t = 0;
this.w = 0;
this.h = 0;
this.s = 0;
this.mv = false;
this.spa = spa[o].style;
this.img = img[o];
this.txt = img[o].alt;
img[o].alt = ""; /* zooming loop */
this.zoom = function()
{
with(this)
{
l += li * s;
t += ti * s;
w += wi * s;
h += hi * s;
if ((s > 0 && w < Wi) || (s < 0 && w > Sx))
{
/* force window.event */
window.focus();
/* loop */
setTimeout("obj[" + o + "].zoom()", 16);
}
else
{
/* finished */
mv = false;
/* set final position */
if (s > 0)
{
l = ix * M + ix * Sx;
t = iy * M + iy * Sy;
w = Wi;
h = Hi;
}
else
{
l = x * M + x * Sx;
t = y * M + y * Sy;
w = Sx;
h = Sy;
}
}
/* html animation */
with(spa)
{
left = px(l);
top = px(t);
width = px(w);
height = px(h);
zIndex = Math.round(w);
}
}
} this.click = function()
{
with(this)
{
img_center(o);
/* zooming logic */
if ( ! mv || cl)
{
if (s > 0)
{
if (cl || Math.abs(xm - xb) > Sx * .4 || Math.abs(ym - yb) > Sy * .4)
{
s = - 2;
mv = true;
zoom();
cap.innerHTML = txt;
}
}
else
{
if (cl || ob != o)
{
if (ob >= 0)
{
with(obj[ob])
{
s = - 2;
mv = true;
zoom();
}
}
ob = o;
s = 1;
xb = xm;
yb = ym;
mv = true;
zoom();
cap.innerHTML = txt;
}
}
}
}
}
/* hook up events */
img[o].onmouseover = img[o].onmousemove = img[o].onmouseout = new Function("cl=false;obj[" + o + "].click()");
img[o].onclick = new Function("cl=true;obj[" + o + "].click()");
img[o].onload = new Function("img_center(" + o + ")"); /* initial display */
this.zoom();
}/* mouse */
document.onmousemove = function(e)
{
if ( ! e)
{
e = window.event;
}
xm = (e.x || e.clientX);
ym = (e.y || e.clientY);
}/* init */
function load()
{
/* html elements */
scr = document.getElementById("screen");
spa = scr.getElementsByTagName("span");
img = scr.getElementsByTagName("img");
cap = document.getElementById("caption");
/* mouseover border */
document.getElementById("border").onmouseover = function()
{
cl = true;
if(ob >= 0 && obj[ob].s > 0) obj[ob].click();
ob = -1;
} /* global variables */
W = parseInt(scr.style.width);
H = parseInt(scr.style.height);
M = W / Mg;
Sx = (W - (Nx - 1) * M) / Nx;
Sy = (H - (Ny - 1) * M) / Ny;
Wi = Tx * Sx + (Tx - 1) * M;
Hi = Ty * Sy + (Ty - 1) * M;
SP = M * Tx * SP;
wi = (Wi - Sx) / SP;
hi = (Hi - Sy) / SP;
/* create objects */
for (k = 0, i = 0; i < Nx; i ++)
{
for (j = 0; j < Ny; j ++)
{
obj[k] = new Cobj(k ++, i, j);
}
}
}
//-->
</script>
</head><body><div style="position: absolute; left: 50%; top: 50%;">
<div id="title" style="position: absolute; width: 440px; height: 40px; left: -220px; top: -200px;">
</div>
<div id="border" style="border: 1px solid rgb(85, 85, 85); background: rgb(0, 0, 0) none repeat scroll 0%; position: absolute; width: 440px; height: 340px; left: -220px; top: -170px; -moz-background-clip: -moz-initial; -moz-background-origin: -moz-initial; -moz-background-inline-policy: -moz-initial;">
</div>
<div id="screen" style="background: rgb(0, 0, 0) none repeat scroll 0%; position: absolute; width: 400px; height: 300px; left: -200px; top: -150px; -moz-background-clip: -moz-initial; -moz-background-origin: -moz-initial; -moz-background-inline-policy: -moz-initial;">
<span style="left: 0px; top: 0px; width: 93px; height: 68px; z-index: 93;"> <img style="left: -11px; top: -9px;" src="images/1.jpg" alt=""></span>
<span style="left: 0px; top: 78px; width: 93px; height: 68px; z-index: 93;"><img style="left: -11px; top: -8px;" src="images/1.jpg" alt=""></span>
<span style="left: 0px; top: 155px; width: 93px; height: 68px; z-index: 93;"><img style="left: -11px; top: -9px;" src="images/1.jpg" alt=""></span>
<span style="left: 0px; top: 233px; width: 93px; height: 68px; z-index: 93;"><img style="left: -11px; top: -9px;" src="images/1.jpg" alt=""></span>
<span style="left: 103px; top: 0px; width: 93px; height: 68px; z-index: 93;"><img style="left: -11px; top: -9px;" src="images/1.jpg" alt=""></span>
<span style="left: 103px; top: 78px; width: 93px; height: 68px; z-index: 93;"><img style="left: -11px; top: -9px;" src="images/1.jpg" alt=""></span>
<span style="left: 103px; top: 155px; width: 93px; height: 68px; z-index: 93;"><img style="left: -11px; top: -9px;" src="images/1.jpg" alt=""></span>
<span style="left: 103px; top: 233px; width: 93px; height: 68px; z-index: 93;"><img style="left: -11px; top: -9px;" src="images/1.jpg" alt=""></span>
<span style="left: 205px; top: 0px; width: 93px; height: 68px; z-index: 93;"><img style="left: -11px; top: -9px;" src="images/1.jpg" alt=""></span>
<span style="left: 205px; top: 78px; width: 93px; height: 68px; z-index: 93;"><img style="left: -11px; top: -9px;" src="images/1.jpg" alt=""></span>
<span style="left: 205px; top: 155px; width: 93px; height: 68px; z-index: 93;"><img style="left: -11px; top: -9px;" src="images/1.jpg" alt=""></span>
<span style="left: 205px; top: 233px; width: 93px; height: 68px; z-index: 93;"><img style="left: -11px; top: -9px;" src="images/1.jpg" alt=""></span>
<span style="left: 308px; top: 0px; width: 93px; height: 68px; z-index: 93;"><img style="left: -11px; top: -9px;" src="images/1.jpg" alt=""></span>
<span style="left: 308px; top: 78px; width: 93px; height: 68px; z-index: 93;"><img style="left: -11px; top: -9px;" src="images/1.jpg" alt=""></span>
<span style="left: 308px; top: 155px; width: 93px; height: 68px; z-index: 93;"><img style="left: -11px; top: -9px;" src="images/1.jpg" alt=""></span>
<span style="left: 308px; top: 233px; width: 93px; height: 68px; z-index: 93;"><img style="left: -11px; top: -9px;" src="images/1.jpg" alt=""></span>
</div>
<div id="caption" style="position: absolute; width: 440px; height: 60px; left: -220px; top: 175px;">test</div>
</div>
<script type="text/javascript"><!--
// starter
load();
//-->
</script></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>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<title>代码(十)</title>
<meta http-equiv="imagetoolbar" content="no">
<style type="text/css">
body {
background: #222;
overflow: hidden;
left: 0;
top: 0;
width: 100%;
height: 100%;
margin: 0;
padding: 0;
}
#screen span {
position:absolute;
overflow:hidden;
border:#FFF solid 1px;
background:#FFF;
}
#screen img{
position:absolute;
left:-32px;
top:-32px;
cursor: pointer;
}
#caption, #title{
color: #FFF;
font-family: georgia, 'times new roman', times, veronica, serif;
font-size: 1em;
text-align: center;
}
#caption b {
font-size: 2em;
}</style>
<script type="text/javascript"><!--
window.onerror = new Function("return true");
var obj = [];
var scr;
var spa;
var img;
var W;
var Wi;
var Hi;
var wi;
var hi;
var Sx;
var Sy;
var M;
var xm;
var ym;
var xb = 0;
var yb = 0;
var ob = - 1;
var cl = false;/* needed in standard mode */
px = function(x)
{
return Math.round(x) + "px";
}/* center image - do not resize for perf. reason */
img_center = function(o)
{
with(img[o])
{
style.left = px( - (width - Wi) / 2);
style.top = px( - (height - Hi) / 2);
}
}//////////////////////////////////////////////////////////
var Nx = 4; //size grid x
var Ny = 4; //size grid y
var Tx = 3; // image width
var Ty = 3; // image height
var Mg = 40; // margin
var SP = 1; // speed
//////////////////////////////////////////////////////////function Cobj(o, x, y)
{
this.o = o;
this.ix = Math.min(Nx - Tx, Math.max(0, Math.round(x - (Tx / 2))));
this.iy = Math.min(Ny - Ty, Math.max(0, Math.round(y - (Ty / 2))));
this.li = ((this.ix * M + this.ix * Sx) - (x * M + x * Sx)) / SP;
this.ti = ((this.iy * M + this.iy * Sy) - (y * M + y * Sy)) / SP;
this.l = 0;
this.t = 0;
this.w = 0;
this.h = 0;
this.s = 0;
this.mv = false;
this.spa = spa[o].style;
this.img = img[o];
this.txt = img[o].alt;
img[o].alt = ""; /* zooming loop */
this.zoom = function()
{
with(this)
{
l += li * s;
t += ti * s;
w += wi * s;
h += hi * s;
if ((s > 0 && w < Wi) || (s < 0 && w > Sx))
{
/* force window.event */
window.focus();
/* loop */
setTimeout("obj[" + o + "].zoom()", 16);
}
else
{
/* finished */
mv = false;
/* set final position */
if (s > 0)
{
l = ix * M + ix * Sx;
t = iy * M + iy * Sy;
w = Wi;
h = Hi;
}
else
{
l = x * M + x * Sx;
t = y * M + y * Sy;
w = Sx;
h = Sy;
}
}
/* html animation */
with(spa)
{
left = px(l);
top = px(t);
width = px(w);
height = px(h);
zIndex = Math.round(w);
}
}
} this.click = function()
{
with(this)
{
img_center(o);
/* zooming logic */
if ( ! mv || cl)
{
if (s > 0)
{
if (cl || Math.abs(xm - xb) > Sx * .4 || Math.abs(ym - yb) > Sy * .4)
{
s = - 2;
mv = true;
zoom();
cap.innerHTML = txt;
}
}
else
{
if (cl || ob != o)
{
if (ob >= 0)
{
with(obj[ob])
{
s = - 2;
mv = true;
zoom();
}
}
ob = o;
s = 1;
xb = xm;
yb = ym;
mv = true;
zoom();
cap.innerHTML = txt;
}
}
}
}
}
/* hook up events */
img[o].onmouseover = img[o].onmousemove = img[o].onmouseout = new Function("cl=false;obj[" + o + "].click()");
img[o].onclick = new Function("cl=true;obj[" + o + "].click()");
img[o].onload = new Function("img_center(" + o + ")"); /* initial display */
this.zoom();
}/* mouse */
document.onmousemove = function(e)
{
if ( ! e)
{
e = window.event;
}
xm = (e.x || e.clientX);
ym = (e.y || e.clientY);
}/* init */
function load()
{
/* html elements */
scr = document.getElementById("screen");
spa = scr.getElementsByTagName("span");
img = scr.getElementsByTagName("img");
cap = document.getElementById("caption");
/* mouseover border */
document.getElementById("border").onmouseover = function()
{
cl = true;
if(ob >= 0 && obj[ob].s > 0) obj[ob].click();
ob = -1;
} /* global variables */
W = parseInt(scr.style.width);
H = parseInt(scr.style.height);
M = W / Mg;
Sx = (W - (Nx - 1) * M) / Nx;
Sy = (H - (Ny - 1) * M) / Ny;
Wi = Tx * Sx + (Tx - 1) * M;
Hi = Ty * Sy + (Ty - 1) * M;
SP = M * Tx * SP;
wi = (Wi - Sx) / SP;
hi = (Hi - Sy) / SP;
/* create objects */
for (k = 0, i = 0; i < Nx; i ++)
{
for (j = 0; j < Ny; j ++)
{
obj[k] = new Cobj(k ++, i, j);
}
}
}
//-->
</script>
</head><body><div style="position: absolute; left: 50%; top: 50%;">
<div id="title" style="position: absolute; width: 440px; height: 40px; left: -220px; top: -200px;">
</div>
<div id="border" style="border: 1px solid rgb(85, 85, 85); background: rgb(0, 0, 0) none repeat scroll 0%; position: absolute; width: 440px; height: 340px; left: -220px; top: -170px; -moz-background-clip: -moz-initial; -moz-background-origin: -moz-initial; -moz-background-inline-policy: -moz-initial;">
</div>
<div id="screen" style="background: rgb(0, 0, 0) none repeat scroll 0%; position: absolute; width: 400px; height: 300px; left: -200px; top: -150px; -moz-background-clip: -moz-initial; -moz-background-origin: -moz-initial; -moz-background-inline-policy: -moz-initial;">
<span style="left: 0px; top: 0px; width: 93px; height: 68px; z-index: 93;"> <img style="left: -11px; top: -9px;" src="images/1.jpg" alt=""></span>
<span style="left: 0px; top: 78px; width: 93px; height: 68px; z-index: 93;"><img style="left: -11px; top: -8px;" src="images/1.jpg" alt=""></span>
<span style="left: 0px; top: 155px; width: 93px; height: 68px; z-index: 93;"><img style="left: -11px; top: -9px;" src="images/1.jpg" alt=""></span>
<span style="left: 0px; top: 233px; width: 93px; height: 68px; z-index: 93;"><img style="left: -11px; top: -9px;" src="images/1.jpg" alt=""></span>
<span style="left: 103px; top: 0px; width: 93px; height: 68px; z-index: 93;"><img style="left: -11px; top: -9px;" src="images/1.jpg" alt=""></span>
<span style="left: 103px; top: 78px; width: 93px; height: 68px; z-index: 93;"><img style="left: -11px; top: -9px;" src="images/1.jpg" alt=""></span>
<span style="left: 103px; top: 155px; width: 93px; height: 68px; z-index: 93;"><img style="left: -11px; top: -9px;" src="images/1.jpg" alt=""></span>
<span style="left: 103px; top: 233px; width: 93px; height: 68px; z-index: 93;"><img style="left: -11px; top: -9px;" src="images/1.jpg" alt=""></span>
<span style="left: 205px; top: 0px; width: 93px; height: 68px; z-index: 93;"><img style="left: -11px; top: -9px;" src="images/1.jpg" alt=""></span>
<span style="left: 205px; top: 78px; width: 93px; height: 68px; z-index: 93;"><img style="left: -11px; top: -9px;" src="images/1.jpg" alt=""></span>
<span style="left: 205px; top: 155px; width: 93px; height: 68px; z-index: 93;"><img style="left: -11px; top: -9px;" src="images/1.jpg" alt=""></span>
<span style="left: 205px; top: 233px; width: 93px; height: 68px; z-index: 93;"><img style="left: -11px; top: -9px;" src="images/1.jpg" alt=""></span>
<span style="left: 308px; top: 0px; width: 93px; height: 68px; z-index: 93;"><img style="left: -11px; top: -9px;" src="images/1.jpg" alt=""></span>
<span style="left: 308px; top: 78px; width: 93px; height: 68px; z-index: 93;"><img style="left: -11px; top: -9px;" src="images/1.jpg" alt=""></span>
<span style="left: 308px; top: 155px; width: 93px; height: 68px; z-index: 93;"><img style="left: -11px; top: -9px;" src="images/1.jpg" alt=""></span>
<span style="left: 308px; top: 233px; width: 93px; height: 68px; z-index: 93;"><img style="left: -11px; top: -9px;" src="images/1.jpg" alt=""></span>
</div>
<div id="caption" style="position: absolute; width: 440px; height: 60px; left: -220px; top: 175px;">test</div>
</div>
<script type="text/javascript"><!--
// starter
load();
//-->
</script></body></html>
解决方案 »
- 求一段JS脚本
- 跪求EXT获取当前选中父节点的Id
- IE8兼容性视力下javascript不能运行
- 简单问题
- 想试着写一个仿scriptaculous的js加载器,但是加载jquery后jquery失效了!贴出来大家帮我看看!
- JS怎么改变每个TD的背景呢????
- table的border设置为1,cellspace设为0,这样发现table的border的宽度还是很宽,如何设置宽度更细一些,好像每个table cell都有一个边框,所以
- 怎样统计输入框地字符,当超过时发出提示???
- 请问:那里还有免费的竹叶空间(现如今,摇头叹气),国外的也行
- 利用闲暇时间做得一个selector孔件,请大家指教
- 火狐浏览器无法正常显示当前日期?
- IE6和IE7兼容问题
//显示缩略图
function DrawImage(ImgD,width_s,height_s){
/*var width_s=139;
var height_s=104;
*/
var image=new Image();
image.src=ImgD.src;
if(image.width>0 && image.height>0){
flag=true;
if(image.width/image.height>=width_s/height_s){
if(image.width>width_s){
ImgD.width=width_s;
ImgD.height=(image.height*width_s)/image.width;
}else{
ImgD.width=image.width;
ImgD.height=image.height;
}
}
else{
if(image.height>height_s){
ImgD.height=height_s;
ImgD.width=(image.width*height_s)/image.height;
}else{
ImgD.width=image.width;
ImgD.height=image.height;
}
}
}
/*else{
ImgD.src="";
ImgD.alt=""
}*/
}
</script>
调用时,很简单,比如一段ASP代码的
<img src="../Images/<%=rs("picpath")%>" align="center" onload="DrawImage(this,200,200)"></div>
http://www.cnblogs.com/zengxiangzhan/archive/2009/09/12/1565323.html