本文目录一览:
- 1、JS脚本实现开关网页放大镜
- 2、javascript放大镜代码
- 3、求帮我添加一个JS放大镜效果
- 4、JS图片放大扩展,按钮开关放大镜
- 5、怎么用javascript代码实现淘宝宝贝图片放大镜效果(鼠标移至小图 显示大图效果),谢谢了
- 6、jquery图片放大镜代码解析注释
JS脚本实现开关网页放大镜
我觉得这个是不是得把当前整个页面复制一份到iframe里面,然后把iframe中的内容缩放。
javascript放大镜代码
同命相连,我也在找这个效果,失望啊!
发现有教程,可是运行不起来,看你会吗?
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=sConvNum2Str(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 p1191 and p1196 then exit do else aso.read(binval2(aso.Read(2))-2)
do:p1=binVal(aso.Read(1)):loop while p1255 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"
""
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("scriptalert('文件加载失败,请确认文件是否存在');history.back(-1);/script")
Response.End()
end if
if (fs.FileExists(filename2)=false) then
Response.Write("scriptalert('文件加载失败,请确认文件是否存在');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 = '';
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 = %=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
求帮我添加一个JS放大镜效果
JS放大镜效果,lz注意下编码问题,图片自己替换 !DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" " " html xmlns=" " head title超逼真的JS图片放大镜/title meta http-equiv="Content-Type" content="text/html; charset=utf-8" / style type="text/css" .zoomPan{width:570px;left:100px;position:relative; } .sh{zoom:1;background:#eee;filter:progid:DXImageTransform.Microsoft.dropShadow(color='#54000000', OffX=2,OffY=2);-webkit-box-shadow:4px 4px 4px #666;-moz-box-shadow:4px 4px 4px #666;} #zoom{position:absolute;width:254px;height:254px;border:3px solid #fff;left:-9999px;top:0;overflow:hidden;background:#fff;} #zoom img{position:relative;} h1{color:#FF0080;border-bottom:5px solid #ddd;padding:10px;} h4{text-align:right;padding:20px;border-top:1px solid #ddd;color:#ccc;} /style /head body h1zoom/h1 div class="zoomPan" id="zoomPan" img src="/jscss/demoimg/201008/s.jpg" alt="" / div id="zoom" class="sh"img src="/jscss/demoimg/201008/b.jpg" alt="" //div /div h4code.js.cn/h4 /body script type="text/javascript" //![CDATA[ function zoomBox() {this.index.apply(this, arguments)} zoomBox.prototype = { index: function(win,zoom) { var win=document.getElementById(win); var box=document.getElementById(zoom); var img=box.getElementsByTagName('IMG')[0]; var zoom=img.width/win.getElementsByTagName('IMG')[0].width; var z=Math.round(box.offsetWidth/2); win.onmousemove=function (e){ e = e || window.event; var x=e.clientX,y=e.clientY, ori=win.getBoundingClientRect(); if (xori.right+20||yori.bottom+20||xori.left-20||yori.top-20)box.style.display='none'; x-=ori.left; y-=ori.top; box.style.left=x-z+'px'; box.style.top=y-z+'px'; img.style.left=-x*zoom+z+'px'; img.style.top=-y*zoom+z+'px'; } win.onmouseover=function (){box.style.display=''} } }; window.onload=function (){ x=new zoomBox('zoomPan','zoom') } //]] /script /html
JS图片放大扩展,按钮开关放大镜
!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" ""
html xmlns=""
head
meta http-equiv="Content-Type" content="text/html; charset=utf-8"/
title放大镜/title
meta name="keywords" content="" /
meta name="Description" content="" /
style type="text/css"
body,div,img {padding:0;margin:0;}
.con {width:256px;height:192px;float:left;}
.con img {width:256px;height:192px;position:absolute;border:1px blue solid;}
.dingwei {position:absolute;width:100px;height:100px;background-color:black;filter:alpha(opacity=20);opacity:0.2;cursor:move;display:none;}
.big {float:left;width:400px;height:400px;margin:100px;overflow:hidden;}
/style
/head
body
div class="con" id="father" style="position:relative;"
img src="images/huo.jpg" alt="图片"/
div id="aa" class="dingwei" /div
/div
div class="big" id="bpic"
div class="inside"img src="images/huo.jpg" alt="图片"//div
/div
script type="text/javascript"
var divs=document.getElementById("aa");
var fa=document.getElementById("father");
var maxWidth=maxHeight=S=0;
var big=document.getElementById("bpic");
fa.onmouseover=function(){
divs.style.display="block";
big.style.display="block";
S=divs.offsetHeight/2;
maxWidth=fa.clientWidth-divs.offsetWidth;
maxHeight=fa.clientHeight-divs.offsetHeight;//物块的活动范围;
}
fa.onmousemove=function(e){
a=e||window.event;
var sbX=a.clientX;
var sbY=a.clientY;
var num=big.clientWidth/divs.clientWidth;
var lf=sbX-S;//鼠标的位置减去元素位置的一半的值就是元素的定位值;
var tp=sbY-S;
//tp =tp0?0:tpmaxHeight?maxHeight:tp;
//lf =lf0?0:lfmaxWidth?maxWidth:lf;//判断物块的定位位置然后进行设置
if(tp0){tp=0;}
else{
if(tpmaxHeight){tp=maxHeight;}
else{tp=sbY-S;}
}
//判断物块的位置进行设置
if(lf0){lf=0;}
else{
if(lfmaxWidth){lf=maxWidth;}
else{lf=sbX-S;}
}
divs.style.left=lf+"px";
divs.style.top=tp+"px";
big.scrollLeft=num*lf;
big.scrollTop=num*tp;
}
fa.onmouseout=function(){
divs.style.display="none";
big.style.display="none";
}
/script
/body
/html
这是放大镜效果的代码 你说的开启和关闭你自己再加上去就行了
怎么用javascript代码实现淘宝宝贝图片放大镜效果(鼠标移至小图 显示大图效果),谢谢了
如果可以用插件的话推荐用jquery插件来实现,一分钟搞定。
如果不能的话就告诉你原理吧,至于具体的实现要做到兼容所有浏览器不是一件省心的事。
首先要准备两张图片(一个是小的预览图,一个是很大的高清图)
然后写一个DIV,里面放一个IMG和一个DIV
也就是
divimg src="预览图地址" /div/div/div
然后给img绑定mousemove事件,在事件内写下如下实现的代码
首先计算出鼠标在这个img标签上的相对坐标,如果是在img的最左上边。坐标则为0,0
然后吧这个DIV内部的小DIV固定为100*100大小,然后再就是计算它的比例。
然后再把这个DIV的背景设置成那个大图,然后再用背景的绝对定位进行移动即可
jquery图片放大镜代码解析注释
(function($){//定义作用域
$.fn.imagezoom=function(options){/*自定义插件imageszoom,options代表形参(属性自定义)*/
var settings={
xzoom: 350, /*放大图的宽度(默认是 350)*/
yzoom: 350, /*放大图的高度(默认是 350)*/
offset: 10, /*离原图的距离(默认是 10)*/
position: "right", /*放大图的定位(默认是 "right")*/
preload:1
};
if(options){
$.extend(settings,options);
}
var noalt='';
var self=this;
$(this).bind("mouseenter",function(ev){/*鼠标经过时添加一个事件处理程序*/
var imageLeft=$(this).offset().left;
var imageTop=$(this).offset().top;
var imageWidth=$(this).get(0).offsetWidth;
var imageHeight=$(this).get(0).offsetHeight;
var boxLeft=$(this).parent().offset().left;
var boxTop=$(this).parent().offset().top;
var boxWidth=$(this).parent().width();
var boxHeight=$(this).parent().height();
noalt=$(this).attr("alt");
var bigimage=$(this).attr("rel");
$(this).attr("alt",'');
if($("div.zoomDiv").get().length==0){
$(document.body).append("div class='zoomDiv'img class='bigimg' src='"+bigimage+"'//div"+
"div class='zoomMask' /div");
}
if(settings.position=="right"){
if(boxLeft+boxWidth+settings.offset+settings.xzoomscreen.width){
leftpos=boxLeft-settings.offset-settings.xzoom;
}else{
leftpos=boxLeft+boxWidth+settings.offset;
}
}else{
leftpos=imageLeft-settings.xzoom-settings.offset;
if(leftpos0){
leftpos=imageLeft+imageWidth+settings.offset;
}
}
$("div.zoomDiv").css({top:boxTop,left:leftpos});
$("div.zoomDiv").width(settings.xzoom);
$("div.zoomDiv").height(settings.yzoom);
$("div.zoomDiv").show();
$(this).css('cursor','crosshair');/*光标呈现十字线*/
$(document.body).mousemove(function(e){/*当移动鼠标时*/
mouse=new MouseEvent(e);
if(mouse.ximageLeft||mouse.ximageLeft+imageWidth||mouse.yimageTop||mouse.yimageTop+imageHeight){
mouseOutImage();/*判断鼠标是否超出图片范围*/
return;
}
var bigwidth=$(".bigimg").get(0).offsetWidth;/*最大宽度*/
var bigheight=$(".bigimg").get(0).offsetHeight;/*最大高度*/
var scaley='x';/*x轴比例 */
var scalex='y';/*y轴比例 */
/*随鼠标移动显示大图*/
if(isNaN(scalex)|isNaN(scaley)){/*x、y轴比例不是数字时*/
var scalex=(bigwidth/imageWidth);
var scaley=(bigheight/imageHeight);
$("div.zoomMask").width((settings.xzoom)/scalex);
$("div.zoomMask").height((settings.yzoom)/scaley);
$("div.zoomMask").css('visibility','visible');/*规定元素可见*/
}
xpos=mouse.x-$("div.zoomMask").width()/2;
ypos=mouse.y-$("div.zoomMask").height()/2;
xposs=mouse.x-$("div.zoomMask").width()/2-imageLeft;
yposs=mouse.y-$("div.zoomMask").height()/2-imageTop;
xpos=(mouse.x-$("div.zoomMask").width()/2imageLeft)
? imageLeft:(mouse.x+$(".zoomMask").width()/2imageWidth+imageLeft)
? (imageWidth+imageLeft-$("div.zoomMask").width()):xpos;
ypos=(mouse.y-$("div.zoomMask").height()/2imageTop)
? imageTop:(mouse.y+$("div.zoomMask").height()/2imageHeight+imageTop)
? (imageHeight+imageTop-$("div.zoomMask").height()):ypos;
$("div.zoomMask").css({top:ypos,left:xpos});
$("div.zoomDiv").get(0).scrollLeft=xposs*scalex;
$("div.zoomDiv").get(0).scrollTop=yposs*scaley;
});
});
function mouseOutImage(){/*定义鼠标离开图片方法*/
$(self).attr("alt",noalt);
$(document.body).unbind("mousemove");/*移除在页面中鼠标指针事件*/
$("div.zoomMask").remove();/*移除所有的div.zoomMask*/
$("div.zoomDiv").remove();/*移除所有的div.zoomDiv*/
}
count=0;
if(settings.preload){
/*在boby元素的结尾(仍然在内部)插入指定内容*/
$('body').append("div style='display:none;' class='jqPreload"+count+"'/div");
$(this).each(function(){/*规定为每个匹配元素规定运行的函数*/
var imagetopreload=$(this).attr("rel");/*图片预加载*/
var content=jQuery('.jqPreload'+count+'').html();
jQuery('.jqPreload'+count+'').html(content+'img src=\"'+imagetopreload+'\"');
});
}
}
})(jQuery);
function MouseEvent(e){/*记录鼠标x,y坐标*/
this.x=e.pageX;/*鼠标指针位置*/
this.y=e.pageY;
}