JS网页图片查看器-可控制图片放大缩小移动|兼容IE、FF

<html>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<title>JS网页图片查看器-可控制图片放大缩小还原移动效果</title>
<META HTTP-EQUIV="imagetoolbar" CONTENT="no">
<style type="text/css">
body { font-family: "Verdana", "Arial", "Helvetica", "sans-serif"; font-size: 12px; line-height: 180%; }
td { font-size: 12px; line-height: 150%; }
</style>
<SCRIPT language=JavaScript>
drag = 0
move = 0

// 拖拽对象
// 参见:http://blog.sina.com.cn/u/4702ecbe010007pe
var ie=document.all;
var nn6=document.getElementById&&!document.all;
var isdrag=false;
var y,x;
var oDragObj;

function moveMouse(e) {
if (isdrag) {
oDragObj.style.top = (nn6 ? nTY + e.clientY - y : nTY + event.clientY - y)+"px";
oDragObj.style.left = (nn6 ? nTX + e.clientX - x : nTX + event.clientX - x)+"px";
return false;
}
}

function initDrag(e) {
var oDragHandle = nn6 ? e.target : event.srcElement;
var topElement = "HTML";
while (oDragHandle.tagName != topElement && oDragHandle.className != "dragAble") {
oDragHandle = nn6 ? oDragHandle.parentNode : oDragHandle.parentElement;
}
if (oDragHandle.className=="dragAble") {
isdrag = true;
oDragObj = oDragHandle;
nTY = parseInt(oDragObj.style.top+0);
y = nn6 ? e.clientY : event.clientY;
nTX = parseInt(oDragObj.style.left+0);
x = nn6 ? e.clientX : event.clientX;
document.οnmοusemοve=moveMouse;
return false;
}
}
document.οnmοusedοwn=initDrag;
document.οnmοuseup=new Function("isdrag=false");

function clickMove(s){
if(s=="up"){
dragObj.style.top = parseInt(dragObj.style.top) + 100;
}else if(s=="down"){
dragObj.style.top = parseInt(dragObj.style.top) - 100;
}else if(s=="left"){
dragObj.style.left = parseInt(dragObj.style.left) + 100;
}else if(s=="right"){
dragObj.style.left = parseInt(dragObj.style.left) - 100;
}

}

function smallit(){
var height1=images1.height;
var width1=images1.width;
images1.height=height1/1.2;
images1.width=width1/1.2;
}

function bigit(){
var height1=images1.height;
var width1=images1.width;
images1.height=height1*1.2;
images1.width=width1*1.2;
}
function realsize()
{
images1.height=images2.height;
images1.width=images2.width;
block1.style.left = 0;
block1.style.top = 0;

}
function featsize()
{
var width1=images2.width;
var height1=images2.height;
var width2=360;
var height2=200;
var h=height1/height2;
var w=width1/width2;
if(height1<height2&&width1<width2)
{
images1.height=height1;
images1.width=width1;
}
else
{
if(h>w)
{
images1.height=height2;
images1.width=width1*height2/height1;
}
else
{
images1.width=width2;
images1.height=height1*width2/width1;
}
}
block1.style.left = 0;
block1.style.top = 0;
}

</SCRIPT>
<script language="JavaScript" type="text/JavaScript">
<!--
function MM_reloadPage(init) { //reloads the window if Nav4 resized
if (init==true) with (navigator) {if ((appName=="Netscape")&&(parseInt(appVersion)==4)) {
document.MM_pgW=innerWidth; document.MM_pgH=innerHeight; οnresize=MM_reloadPage; }}
else if (innerWidth!=document.MM_pgW || innerHeight!=document.MM_pgH) location.reload();
}
MM_reloadPage(true);
//-->
</script>
<style type="text/css">
<!--
td, a { font-size:12px; color:#000000 }
#Layer1 { position:absolute; z-index:100; top: 10px; }
#Layer2 { position:absolute; z-index:1; }
-->
</style>
</head>
<body leftmargin="0" topmargin="0" marginwidth="0" marginheight="0" οncοntextmenu="return false" οndragstart="return false" onselectstart ="return false" οnselect="document.selection.empty()" οncοpy="document.selection.empty()" onbeforecopy="return false" οnmοuseup="document.selection.empty()" style="overflow-y:hidden;overflow-x:hidden;">
<div id="Layer1">
<table border="0" cellspacing="2" cellpadding="0">
<tr>
<td> </td>
<td><img src="http://img.jb51.net/images/map/up.gif" width="20" height="20" style="cursor:hand" onClick="clickMove('up')" title="向上"></td>
<td> </td>
</tr>
<tr>
<td><img src="http://img.jb51.net/images/map/left.gif" width="20" height="20" style="cursor:hand" onClick="clickMove('left')" title="向左"></td>
<td><img src="http://img.jb51.net/images/map/zoom.gif" width="20" height="20" style="cursor:hand" onClick="realsize();" title="还原"></td>
<td><img src="http://img.jb51.net/images/map/right.gif" width="20" height="20" style="cursor:hand" onClick="clickMove('right')" title="向右"></td>
</tr>
<tr>
<td> </td>
<td><img src="http://img.jb51.net/images/map/down.gif" width="20" height="20" style="cursor:hand" onClick="clickMove('down')" title="向下"></td>
<td> </td>
</tr>
<tr>
<td> </td>
<td><img src="http://img.jb51.net/images/map/zoom_in.gif" width="20" height="20" style="cursor:hand" onClick="bigit();" title="放大"></td>
<td> </td>
</tr>
<tr>
<td> </td>
<td><img src="http://img.jb51.net/images/map/zoom_out.gif" width="20" height="20" style="cursor:hand" onClick="smallit();" title="缩小"></td>
<td> </td>
</tr>
</table>
</div>

 
<div id='hiddenPic' style='position:absolute; left:0px; top:0px; width:0px; height:0px; z-index:1; visibility: hidden;'><img name='images2' src='http://img.jb51.net/images/map/760-480bsx.jpg' border='0'></div>
<div id='block1' οnmοuseοut='drag=0' οnmοuseοver='dragObj=block1; drag=1;' style='z-index:10; height: 0; left: 0px; position: absolute; top: 0px; width: 0' class="dragAble"> <img name='images1' src='http://img.jb51.net/images/map/760-480bsx.jpg' border='0'></div>
</body>
</html>

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
以下是一个简单的HTML实现在线图片查看器的示例代码。它使用了jQuery和fancybox库来实现图片放大缩小和下载功能。 ```html <!DOCTYPE html> <html> <head> <title>在线图片查看器</title> <meta charset="UTF-8"> <link rel="stylesheet" type="text/css" href="//cdn.bootcss.com/fancybox/3.5.7/jquery.fancybox.min.css"> <style> .gallery { display: flex; flex-wrap: wrap; justify-content: center; } .gallery img { margin: 10px; max-width: 200px; cursor: pointer; } </style> </head> <body> <div class="gallery"> <img src="https://picsum.photos/id/1/200/200" data-src="https://picsum.photos/id/1/800/800" alt="图片1"> <img src="https://picsum.photos/id/2/200/200" data-src="https://picsum.photos/id/2/800/800" alt="图片2"> <img src="https://picsum.photos/id/3/200/200" data-src="https://picsum.photos/id/3/800/800" alt="图片3"> <img src="https://picsum.photos/id/4/200/200" data-src="https://picsum.photos/id/4/800/800" alt="图片4"> <img src="https://picsum.photos/id/5/200/200" data-src="https://picsum.photos/id/5/800/800" alt="图片5"> </div> <script src="//cdn.bootcss.com/jquery/3.3.1/jquery.min.js"></script> <script src="//cdn.bootcss.com/fancybox/3.5.7/jquery.fancybox.min.js"></script> <script> $(document).ready(function() { $('.gallery img').click(function() { var src = $(this).data('src'); $.fancybox.open({ src: src, type: 'image', buttons: [ 'zoom', 'slideShow', 'fullScreen', 'download', 'thumbs', 'close' ] }); }); }); </script> </body> </html> ``` 这段代码中,我们首先定义了一个名为“gallery”的div容器,其中包含了5张图片,每张图片都有一个原始的低分辨率版本和一个高分辨率版本,高分辨率版本的地址保存在“data-src”属性中。 接下来,我们引入了jQuery和fancybox库,并使用jQuery选择器来获取所有的图片元素,并为它们添加一个点击事件。当用户点击图片时,我们使用fancybox库打开它的高分辨率版本,并启用了放大缩小、下载等功能按钮。 需要注意的是,由于fancybox库需要从远程服务器加载相关资源,所以我们在代码中使用了CDN来加载这些资源,以提高页面加载速度。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值