当前位置:首页 » JavaScript技术

Javascript实现图片放大镜效果

2006-09-22 08:33 本站整理 浏览(6)
picclass.asp 图片处理类文件
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<%
'//////////// GPS:Get Picture Size //////////////
'//////////////利用ADODB.stream获取图片尺寸//////////////
'/////////Cited By Leon(心晴) 2005年8月11日//////////
Class GPS
Dim aso
Private Sub Class_Initialize
Set aso=CreateObject("Adodb.Stream")
aso.Mode=3
aso.Type=1
aso.Open
End Sub
Private Sub Class_Terminate
set aso=nothing
End Sub
Private Function Bin2Str(Bin)
Dim I, Str
For I=1 to LenB(Bin)
clow=MidB(Bin,I,1)
if AscB(clow)<128 then
Str = Str & Chr(ASCB(clow))
Else
I=I+1
if I <= LenB(Bin) then Str = Str & Chr(ASCW(MidB(Bin,I,1)&clow))
end If
Next
Bin2Str = Str
End Function
Private Function Num2Str(num,base,lens)
'GPS (2005-8-11)
dim ret
ret = ""
while(num>=base)
ret = (num mod base) & ret
num = (num - num mod base)/base
wend
Num2Str = right(string(lens,"0") & num & ret,lens)
End Function
Private Function Str2Num(str,base)
'GPS (2005-8-11)
dim ret
ret = 0
for i=1 to len(str)
ret = ret *base + cint(mid(str,i,1))
next
Str2Num=ret
End Function
Private Function BinVal(bin)
'GPS (2002-8-11)
dim ret
ret = 0
for i = lenb(bin) to 1 step -1
ret = ret *256 + ascb(midb(bin,i,1))
next
BinVal=ret
End Function
Private Function BinVal2(bin)
'GPS (2002-8-11)
dim ret
ret = 0
for i = 1 to lenb(bin)
ret = ret *256 + ascb(midb(bin,i,1))
next
BinVal2=ret
End Function
'///以下是调用代码///
Function getImageSize(filespec)
'GPS (2002-8-11)
dim ret(3)
aso.LoadFromFile(filespec)
bFlag=aso.read(3)
select case hex(binVal(bFlag))
case "4E5089":
aso.read(15)
ret(0)="PNG"
ret(1)=BinVal2(aso.read(2))
aso.read(2)
ret(2)=BinVal2(aso.read(2))
case "464947":
aso.read(3)
ret(0)="GIF"
ret(1)=BinVal(aso.read(2))
ret(2)=BinVal(aso.read(2))
case "535746":
aso.read(5)
binData=aso.Read(1)
sConv=Num2Str(ascb(binData),2 ,8)
nBits=Str2Num(left(sConv,5),2)
sConv=mid(sConv,6)
while(len(sConv)<nBits*4)
binData=aso.Read(1)
sConv=sConv&Num2Str(ascb(binData),2 ,8)
wend
ret(0)="SWF"
ret(1)=int(abs(Str2Num(mid(sConv,1*nBits+1,nBits),2)-Str2Num(mid
(sConv,0*nBits+1,nBits),2))/20)
ret(2)=int(abs(Str2Num(mid(sConv,3*nBits+1,nBits),2)-Str2Num(mid
(sConv,2*nBits+1,nBits),2))/20)
case "FFD8FF":
do
do: p1=binVal(aso.Read(1)): loop while p1=255 and not aso.EOS
if p1>191 and p1<196 then exit do else aso.read(binval2(aso.Read(2))-2)
do:p1=binVal(aso.Read(1)):loop while p1<255 and not aso.EOS
loop while true
aso.Read(3)
ret(0)="JPG"
ret(2)=binval2(aso.Read(2))
ret(1)=binval2(aso.Read(2))
case else:
if left(Bin2Str(bFlag),2)="BM" then
aso.Read(15)
ret(0)="BMP"
ret(1)=binval(aso.Read(4))
ret(2)=binval(aso.Read(4))
else
ret(0)=""
end if
end select
ret(3)="width=""" & ret(1) &""" height=""" & ret(2) &""""
getimagesize=ret
End Function
End Class
%>
图片调用文件
<%@LANGUAGE="VBSCRIPT" CODEPAGE="65001"%>
<!--#include file="picclass.asp"-->
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<head>
<SCRIPT LANGUAGE="JAVASCRIPT">
  <!--
function maxview(){
if (window.screen){
var w=screen.availwidth;
var h=screen.availheight;
window.moveTo(0,0);
window.resizeTo(w,h);
}
}
  // -->
  </SCRIPT>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title></title>
<SCRIPT src="zoom.js" type=text/javascript></SCRIPT>
</head>
<body onLoad="maxview(); OnLoadMainFunction();">
<table width="905" border="0" align="center" cellpadding="15" cellspacing="1">
<tr>
<td valign="top" bgcolor="#FFFFFF"><table width="100%" border="0" cellspacing="15"
cellpadding="0">
<tr>
<td valign="top">
<%
if request("showid")<>"" then
sql="update lei_product set dianjishu=dianjishu+1 where id="&(request("showid"))
conn.execute(sql)
set rs=server.CreateObject("adodb.recordset")
showstr="select * from lei_product where id="& (request("showid"))
rs.open showstr,conn,1,1
if not rs.bof and not rs.eof then
'/////获取ShowImg.asp的绝对路径/////
Dim curFile
curFile=Server.mappath(Request.servervariables("PATH_INFO"))
Dim curfilename,filename
'/////图片相对路径(存于数据库中)
'cufilename=rs("ImgURL")
cufilename="../admin/upimg/"&rs("bigimg2")
cufilename2="../admin/upimg/"&rs("bigimg")
'/////因为ShowImg.asp与images在同一目录,所以我们用instrrev获取images的路径/////
filename=left(curFile,instrrev(curFile,"/"))&cufilename
filename2=left(curFile,instrrev(curFile,"/"))&cufilename2
'/////建立GPS类实体/////
Dim GetPicSize
Set GetPicSize=new GPS
Set fs=Server.CreateObject("Scripting.FileSystemObject")
'/////获取图片类型/////
Dim PicSuffixName
Dim PicSuffixName2
if (fs.FileExists(filename)=false) then
Response.Write("<script>alert('文件加载失败,请确认文件是否存在');history.back(-
1);</script>")
Response.End()
end if
if (fs.FileExists(filename2)=false) then
Response.Write("<script>alert('文件加载失败,请确认文件是否存在');history.back(-
1);</script>")
Response.End()
end if
PicSuffixName=fs.GetExtensionName(filename)
PicSuffixName2=fs.GetExtensionName(filename2)
Dim PD '//Picture Dimension
Dim PD2 '//Picture Dimension
Dim PWidth,PHeight
Dim PWidth2,PHeight2
PD=GetPicSize.GetImageSize(filename)
PD2=GetPicSize.GetImageSize(filename2)
PWidth=PD(1) '//获取图片宽度
PWidth2=PD2(1) '//获取图片宽度
PHeight=PD(2) '//获取图片高度
PHeight2=PD2(2) '//获取图片高度
Set fs=Nothing
Set GetPicSize=Nothing
%>
<SCRIPT type=text/javascript>
var usezoom = 1;
var itemimagedir = '../admin/upimg/';
var zoom_bigimagediv = 'bigimagediv';
var zoom_bigimagetablediv = 'bigimagetablediv';
var zoom_highlightdiv = 'highlightdiv';
var zoom_bigimageouterdiv = 'bigimageouterdiv';
var zoom_viewportwid = 400;//大图图片显示区域
var zoom_viewporthei = 320;//大图片显示区域
var zoom_mainimagewid = <%=PWidth2%>;//小图宽
//var zoom_mainimagehei = 359.714285714286;
var zoom_mainimagehei = <%=PHeight2%>;//小图高
var zoom_mainimageurl = '../admin/upimg/<%=rs("bigimg2")%>';
var zoom_zoomimagewid = <%=PWidth%>;//原图大小宽
var zoom_zoomimagehei = <%=PHeight%>;//原图大小高
var zoom_zoomimageurl = '../admin/upimg/<%=rs("bigimg2")%>';//大图地址
var zoom_bigimagetablexoffset = 1;
var zoom_bigimagetableyoffset = 21;
var zoom_displayxposition = 0;
var zoom_displayyposition = 0;
var zoom_miniimagex = 0;
var zoom_miniimagey = 0;
var zoom_highlightbgcolor = 'ffffff';
var zoom_highlightimage = 'highlight.gif';
function GetZoomObjectData() {
var position;
if (!InIE && !InNS6 && !DOMCompatible)
return;
position = MeMSOObjectGetPosition('mainimage');
zoom_miniimagex = position.x;
zoom_miniimagey = position.y;
position = MeMSOObjectGetPosition('locatezoomim');
zoom_displayxposition = position.x;//显示图片的位置
zoom_displayyposition = position.y - 21;
Zoom_StartupZoomRegion();
}
onloadlist += 'GetZoomObjectData();';
</SCRIPT>
<table width="100%" border="0" align="center" cellpadding="0" cellspacing="1">
<tr>
<td bgcolor="#FFFFFF"> <div align="center">
<table cellspacing="0" cellpadding="0" width="100%" border="0">
<tbody>
<tr>
<td valign="center" align="middle" rowspan="4"><table cellspacing="1"
cellpadding="2" width="<%=PWidth2%>"
bgcolor="#efe6dd" border="0" height="<%=PHeight2%>">
<tbody>
<tr>
<td bgcolor="#ffffff"><img
src="../admin/upimg/<%=rs("bigimg")%>" name="mainimage"
border="0" width="<%=PWidth2%>" height="<%=PHeight2%>"
id="mainimage" /></td>
</tr>
</tbody>
</table>
<br />
<a href="#" target="_blank">点击看大图</a></td>
<td valign="bottom" align="left" height="5"><img height="5"
src="dot_line.gif" width="401" /></td>
</tr>
<tr>
<td valign="bottom" align="left" width="420" height="1"><table cellspacing="0"
cellpadding="0" width="100%"
border="0">
<tbody>
<tr>
<td colspan="2"><img id="locatezoomim" height="1"
src="dot_1.gif" width="1"
name="locatezoomim" /></td>
</tr>
</tbody>
</table></td>
</tr>
<tr>
<td valign="top" align="left" width="425"
background="bigImg.gif"
height="330"><p>  </p></td>
</tr>
<tr>
<td align="middle"><div id="highlightdiv"
style="Z-INDEX: 2; LEFT: -2000px; POSITION: absolute; TOP: -2000px;
visibility: hidden;"></div>
<div id="bigimageouterdiv"
style="Z-INDEX: 4; LEFT: -2000px; VISIBILITY: visible; OVERFLOW:
hidden; WIDTH: 300px; POSITION: absolute; TOP: -2000px; HEIGHT: 300px">
<div id="bigimagediv"
style="Z-INDEX: 4; LEFT: -2000px; POSITION: absolute; TOP: -2000px;
visibility: hidden;"><img
id="mainzoomimage" height="2400" src="" width="800" border="0"
name="mainzoomimage" /></div>
</div>
<div id="bigimagetablediv" style="Z-INDEX: 3; LEFT: -2000px; POSITION:
absolute; TOP: -2000px; visibility: hidden;"></div></td>
</tr>
</tbody>
</table>
</div>
<div align="right"></div></td>
</tr>
</table>
<%end if
rs.close
set rs = nothing
%>
<%end if
%>
</td>
</tr>
</table></td>
</tr>
</table>
<table width="905" height="8" border="0" align="center" cellpadding="0" cellspacing="0">
<tr>
<td></td>
</tr>
</table>
</body>
</html>
zoom.js 文件