js点击图片查看大图,并可以拖动,且滚动滑轮放大缩小

方法一:此方法在页面没有滚动条时无法缩放

 

JQuery

function hideMax(){$(".MAX_div").remove();$("#Cover_Div").hide();}function showMax(url){$("#Cover_Div").show();var Image=function(){return document.createElement("img");}  var DIV=function(){return document.createElement("div");}          var div=new DIV();    var close_div=new DIV();var close_img=new Image();    var img=new Image();var _enter=false;$(".MAX_div").remove();div.setAttribute("class","MAX_div");close_div.setAttribute("class","close");close_div.setAttribute("title","点击关闭");img.setAttribute("class","showMax");img.src=url;close_img.src="tpl/images/delete.png";img.onmouseover=function(){_enter=true;}img.onmouseout=function(){_enter=false;}close_div.onclick=function(){hideMax();}close_div.appendChild(close_img);div.appendChild(img);div.appendChild(close_div);document.body.appendChild(div);//var _z=9999;var close=$(".close");$(document).ready(function(){var _move=false;//移动标记var _x,_y;//鼠标离控件左上角的相对位置var wd;//窗口$(".showMax").click(function(){//alert("click");//点击(松开后触发)//this.style.cursor = "default";//鼠标形状//this.style.zIndex = 999;}).mousedown(function(e){_move=true;wd=$(this);//this.style.cursor = "move";//鼠标形状// this.style.zIndex = _z;//窗口层次// _z++;_x=e.pageX-(isNaN(parseInt(wd.css("left")))?0:parseInt(wd.css("left")));_y=e.pageY-(isNaN(parseInt(wd.css("top")))?0:parseInt(wd.css("top")));       c_x=e.pageX-(isNaN(parseInt(close.css("left")))?0:parseInt(close.css("left")));c_y=e.pageY-(isNaN(parseInt(close.css("top")))?0:parseInt(close.css("top"))); /*  wd.fadeTo(20, 0.25); *///点击后开始拖动并透明显示$(document).mousemove(function(e){if(_move){var x=e.pageX-_x;//移动时根据鼠标位置计算控件左上角的绝对位置var y=e.pageY-_y;var closeX=e.pageX-c_x;var closeY=e.pageY-c_y;wd.css({top:y,left:x});//控件新位置
                            close.css({top:closeY,left:closeX});}}).mouseup(function(){_move=false;/* wd.fadeTo("fast", 1); *///松开鼠标后停止移动并恢复成不透明
                  });});});//$(".showMax").mouseover(function(){var scrollTop = $(window).scrollTop();var initTop=scrollTop;var screenheight = window.screen.availHeight; //获取屏幕高   $(window).scroll( function() { scrollTop = $(window).scrollTop();;var w=parseInt($(".showMax").css("width"));var h=parseInt($(".showMax").css("height"));if(scrollTop > initTop&&_enter){$(".showMax").css({"width":w+Number(28)+"px","height":h+Number(50)+"px"});close.css("margin-left",(w-125)<125?125:(w-125)+"px");$(window).scrollTop(initTop);//保持滚动条距离底部0px 
                        } if(scrollTop <initTop&&_enter){$(".showMax").css({"width":(w-28)<280?280:(w-28)+"px","height":(h-50)<500?500:(h-50)+"px"});close.css("margin-left",(w-155-28)<125?125:(w-155-28)+"px");$(window).scrollTop(initTop);//保持滚动条距离底部0px 
                        }//initTop=scrollTop;   
                });//})function imgdragstart(){return false;}  for(i in document.images)document.images[i].οndragstart=imgdragstart; }

CSS

.showMax{padding:5px;padding-top:30px;border-radius:3px;position:fixed;z-index:999991;top:25%;width:280px;height:500px;left:50%;margin-left:-140px;background-color:orange;cursor:move;    
}
.MAX_div{}
.close{color:#ffffff;position:fixed;z-index:999992;width:14px;height:14px;top:25%;left:50%;margin-left:125px;margin-top:8px;}
li >img:hover{border:1px solid orange;cursor:crosshair;
}
#Cover_Div{position: fixed;z-index: 9999; width: 100%;height: 100%; left: 0; top: 0;min-width: 700px;min-height: 740px;      opacity: 0.5; filter: alpha(opacity = 50); background-color: #ffffff; 
display:none; } .cut{font-weight:bold;font-weight:normal\0;font-size:18px;height:30px;max-height:35px;color:#FFFFFF;font-family:楷书; }

Html

<img  onclick="showMax('url")"  src="url" style="width:288px;height:216px;" />
<div id="Cover_Div" onClick="hideMax()"></div>

 方法二:

JS(其它同上)

function hideMax(){$(".MAX_div").remove();$("#Cover_Div").hide();}var _enter=false;var scrollFunc = function (e) {e = e || window.event;

if(_enter){
if (e&&e.preventDefault){
e.preventDefault();
e.stopPropagation();
}else{
e.returnvalue=false;
}
}

var w=parseInt($(".showMax").css("width"));var h=parseInt($(".showMax").css("height"));if (e.wheelDelta&&_enter) {  //判断浏览器IE,谷歌滑轮事件             if (e.wheelDelta > 0) { //当滑轮向上滚动时$(".showMax").css({"width":w+Number(28)+"px","height":h+Number(50)+"px"});$(".close").css("margin-left",(w-125)<125?125:(w-125)+"px");}if (e.wheelDelta < 0) { //当滑轮向下滚动时$(".showMax").css({"width":(w-28)<280?280:(w-28)+"px","height":(h-50)<500?500:(h-50)+"px"});$(".close").css("margin-left",(w-155-28)<125?125:(w-155-28)+"px");}} else if (e.detail&&_enter) {  //Firefox滑轮事件if (e.detail> 0) { //当滑轮向下滚动时
                 $(".showMax").css({"width":(w-28)<280?280:(w-28)+"px","height":(h-50)<500?500:(h-50)+"px"});$(".close").css("margin-left",(w-155-28)<125?125:(w-155-28)+"px");
             } 
if (e.detail< 0) { //当滑轮向上滚动时

                 $(".showMax").css({"width":w+Number(28)+"px","height":h+Number(50)+"px"});$(".close").css("margin-left",(w-125)<125?125:(w-125)+"px");
          }
} }
//给页面绑定滑轮滚动事件

if (document.addEventListener) {
//webkit
document.addEventListener('mousewheel', scrollFunc, false);
//firefox
document.addEventListener('DOMMouseScroll', scrollFunc, false);

}else if(window.attachEvent){//IE
document.attachEvent('onmousewheel',scrollFunc);
}

function showMax(url){$("#Cover_Div").show();var Image=function(){return document.createElement("img");}  var DIV=function(){return document.createElement("div");}          var div=new DIV();    var close_div=new DIV();var close_img=new Image();    var img=new Image();$(".MAX_div").remove();div.setAttribute("class","MAX_div");close_div.setAttribute("class","close");close_div.setAttribute("title","点击关闭");img.setAttribute("class","showMax");img.src=url;close_img.src="img/delete.png";img.onmouseover=function(){_enter=true;}img.onmouseout=function(){_enter=false;}close_div.onclick=function(){hideMax();}close_div.appendChild(close_img);div.appendChild(img);div.appendChild(close_div);document.body.appendChild(div);//var _z=9999;var close=$(".close");$(document).ready(function(){var _move=false;//移动标记var _x,_y;//鼠标离控件左上角的相对位置var wd;//窗口$(".showMax").click(function(){//alert("click");//点击(松开后触发)//this.style.cursor = "default";//鼠标形状//this.style.zIndex = 999;}).mousedown(function(e){_move=true;wd=$(this);//this.style.cursor = "move";//鼠标形状// this.style.zIndex = _z;//窗口层次// _z++;_x=e.pageX-(isNaN(parseInt(wd.css("left")))?0:parseInt(wd.css("left")));_y=e.pageY-(isNaN(parseInt(wd.css("top")))?0:parseInt(wd.css("top")));       c_x=e.pageX-(isNaN(parseInt(close.css("left")))?0:parseInt(close.css("left")));c_y=e.pageY-(isNaN(parseInt(close.css("top")))?0:parseInt(close.css("top"))); /*  wd.fadeTo(20, 0.25); *///点击后开始拖动并透明显示$(document).mousemove(function(e){if(_move){var x=e.pageX-_x;//移动时根据鼠标位置计算控件左上角的绝对位置var y=e.pageY-_y;var closeX=e.pageX-c_x;var closeY=e.pageY-c_y;wd.css({top:y,left:x});//控件新位置
                            close.css({top:closeY,left:closeX});}}).mouseup(function(){_move=false;/* wd.fadeTo("fast", 1); *///松开鼠标后停止移动并恢复成不透明
                  });});});//禁止拖动页面图片在新窗口打开function imgdragstart(){return false;}  for(i in document.images)document.images[i].οndragstart=imgdragstart; }

 

转载于:https://www.cnblogs.com/oospace/p/4250898.html

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.mzph.cn/news/291941.shtml

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

太努力工作的年轻人,都有病吧!?

全世界只有3.14 % 的人关注了爆炸吧知识前段时间&#xff0c;有人这样问超模君&#xff1a;为什么年轻人明明没有老一辈辛苦&#xff0c;病却反而更多了&#xff1f;在这个物质丰富的年代&#xff0c;如果你退出这场无限内卷的社畜游戏&#xff0c;选择躺平就会活得很轻松&…

lsattr/chattr

lsattr/chattr主要用于特殊权限可以用lsattr直接查看当前目录下所有文件和目录的特殊属性 默认只有一个e &#xff08;ext4 /ext3&#xff09;chattr a 111.txtlsattr 111.txt就会发现多了一个a 那么这个a权限有什么意义呢&#xff1f;我们来编辑一下111.txt 随便输入一些&…

linux之学习之路

很多同学接触Linux不多&#xff0c;对Linux平台的开发更是一无所知。 而现在的趋势越来越表明&#xff0c;作为一个优秀的软件开发人员&#xff0c;或计算机IT行业从业人员&#xff0c; 掌握Linux是一种很重要的谋生资源与手段。 下来我将会结合自己的几年的个人开发经验&…

xshell中重启指令_Xshell命令大全

(1)命令ls-----列出文件ls -la给出当前目录下所有文件的一个长列表&#xff0c;包括以句点开头的“隐藏”文件ls a*列出当前目录下以字母a开头的所有文件la -l *.doc 给出当前目录下以.doc结尾的所有文件(2)命令cp——复制文件cp afile afile.bak 把文件复制为新文件afile.bakc…

在线自动下载最新版本jquery

<script src"http://code.jquery.com/jquery-latest.js"> 转载于:https://www.cnblogs.com/IcanFixIt/p/4253279.html

高考成绩接近满分,却被清华北大拒绝,被称“中国最帅科学家”

全世界只有3.14 % 的人关注了爆炸吧知识有一段时间&#xff0c;超模君刷微博的时候&#xff0c;发现微博热搜第一是“我国又发现10亿吨级大油田”这个话题&#xff0c;不愧是硬核礼物——“真我为祖国献石油”&#xff01;微博热搜第一话题作为一名热爱祖国的十八线网红&#x…

自古以来,JSON序列化就是兵家必争之地

上文讲到使用ioutil.ReadAll读取大的Response Body&#xff0c;出现读取Body超时的问题。01前人引路Stackoverflow[1]的morganbaz的看法是&#xff1a;使用iotil.ReadAll去读取go语言里大的Response Body&#xff0c;是非常低效的; 另外如果Response Body足够大&#xff0c;还有…

实验三《实时系统的移植》 20145222黄亚奇 20145213祁玮

北京电子科技学院&#xff08;BESTI&#xff09; 实 验 报 告 封 面 课程&#xff1a;信息安全系统设计基础 班级&#xff1a;1452 姓名&#xff1a; 黄亚奇 祁玮 学号&#xff1a; 20145222 20145213 成绩&#xff1a; 指导教师&#xff1a;娄嘉鹏 实验日期&#xff1a;2016.1…

linux c之通过popen和pclose函数创建管道执行shell 运行命令使用总结

1、函数介绍 popen 和 pclose 函数 操作是创建一个管道链接到另一个进程,然后读其输出或向其输入端发送数据。标准 I/O 库提供了两个函数 popen 和 pclose 函数,这两个函数实现的操作是:创建一个管道,调用 fork 创建一个子进程,关闭管道的不使用端,执行一个 shell 以运行…

python内置函数 pdf_关于Python巧妙而强大的内置函数

python内置了一些非常巧妙而且强大的内置函数&#xff0c;对初学者来说&#xff0c;一般不怎么用到&#xff0c;我也是用了一段时间python之后才发现&#xff0c;哇还有这么好的函数&#xff0c;这个函数都是经典的而且经过严格测试的,可以一下子省了你原来很多事情&#xff0c…

nginx获得response自定义的header

Response header send by upstream is $upstream_http_x_uuid http://wiki.nginx.org/HttpUpstreamModule#.24upstream_http_.24HEADER $upstream_http_$HEADER Arbitrary HTTP protocol headers, for example: $upstream_http_host$http_x_* is header sent by client. 转载于…

欢迎来到元宇宙的虚拟世界

众所周知&#xff0c;由于这次疫情&#xff0c;给我们的生活造成了很多不便。现在&#xff0c;让我们进入未来科技世界, 我想很多人都听说过 元宇宙 这个词&#xff0c;大家可能对这个新的概念有很多疑问, 什么是元宇宙? 这是什么新技术? 在即将到来的未来会带来怎样的变化&a…

checking size of char… configure: error: cannot compute sizeof (char) 解决方法

今天在编译freeswitch时 报了这个错误&#xff0c;看config.log 发现最后在测试一些lib的时候出错了。 先按configure的--with选项处理无效。config.log依然同样的错误 最后export LD_LIBRARY_PATH/lib/:/usr/lib/:/usr/local/lib 再configure就可以了。 参考http://www.recoye…

jQuery子页面获取父页面元素

$("input[typecheckbox]:checked",window.opener.document);//适用于打开窗口的父页面元素获取 $("input[typecheckbox]:checked",parent.document);//适用于iframe子页面获取父页面元素 转载于:https://www.cnblogs.com/lxcmyf/p/6189478.html

linux c之通过管道父子进程实现同步通信

1、父进程向子进程写数据 进程的概念和父进程向子进程写数据&#xff0c;我们之前有一片博客介绍过 http://blog.csdn.net/u011068702/article/details/54914774 linux c之管道的介绍、创建关闭和简单读写&#xff08;父进程向子进程写入数据&#xff09; 2、父子进程实现同…

attiny13a程序实例_ATtiny13A图文构成

Features•High Performance, Low Power AVR8-Bit Microcontroller•Advanced RISC Architecture–120 Powerful Instructions – Most Single Clock Cycle Execution–32 x 8 General Purpose Working Registers–Fully Static Operation–Up to 20 MIPS Througput at 20 MHz•…

MySQL导入数据load data infile用法

MySQL导入数据load data infile用法 基本语法&#xff1a; load data [low_priority] [local] infile file_name txt [replace | ignore] into table tbl_name [fields [terminated byt] [OPTIONALLY] enclosed by ] [escaped by\ ]] [lines terminated byn] [ignore number li…

11G Oracle RAC添加新表空间时数据文件误放置到本地文件系统的修正

今天看了一篇文章说是误将新创建的表空间的数据文件放置在了本地系统而不是共享存储上。是Oracle的中文技术支持博客题目是&#xff1a;RAC中误将数据文件创建在本地盘时的修正于是我想11G 也兼容这些操作的方法&#xff0c;但是11G的新特性有一点就是可以直接支持ASM文件系统直…

sql练习(针对Mysql)

创建表: 1 DROP TABLE DEPT;2 --部门表3 CREATE TABLE DEPT(4 DEPTNO int PRIMARY KEY,5 DNAME VARCHAR(14) , --部门名称6 LOC VARCHAR(13) ---部门地址7 ) ;8 9 CREATE TABLE DEPT( 10 DEPTNO int PRIMARY KEY, 11 DNAME VARCHAR(14) , 12 …

.NET6之MiniAPI(十二):引入EntityFramewor

说明&#xff1a;本篇重点说明MiniAPI引入EntityFramework&#xff0c;EF的使用不是本篇的重点本篇是在MiniAPI中使用EntityFramework&#xff0c;所以先奉上创建数据的脚本&#xff0c;数据库是SQL Server&#xff0c;可能版本不同&#xff0c;会有一些问题&#xff0c;可以自…