jquery自定义弹层显示大图(兼容多层iframe)
1、介绍
a:可用于多层iframe中,显示在最外层
b:动画效果为从点击的图片位置开始放大至全屏显示
2、效果图


3、js代码
1 function ShowMaxImg(src, y, x, w, h) {
2 var str = '<section id="ShowMaxImgBox">';
3 str += '<div class="button button-primary ShowMaxImgClose" onclick="window.top.RemoveMaxImg(' + y + ',' + x + ',' + w + ',' + h + ')">';
4 str += '<i class="ion ion-close"></i>';
5 str += '</div>';
6 str += '<section class="ShowMaxImgBg" style=\'width:' + w + 'px;height:' + h + 'px;top:' + y + 'px;left:' + x + 'px;background-image:url(' + src + ')\' onclick="window.top.RemoveMaxImg(' + y + ',' + x + ',' + w + ',' + h + ')">';
7 str += '</section>';
8 str += '</section>';
9 $("#ShowMaxImgBox").remove();
10 window.top.$("body").append(str);
11 window.top.$("#ShowMaxImgBox .ShowMaxImgBg").animate({ "height": "100vh", "width": "100vw", "left": "0", "top": "0" }, 300, "swing");
12 }
13 function RemoveMaxImg(y, x, w, h) {
14 $("#ShowMaxImgBox .ShowMaxImgBg").animate({ "height": h + "px", "width": w + "px", "left": x + "px", "top": y + "px" }, 300, "swing", function () {
15 $("#ShowMaxImgBox").remove();
16 });
17 }
18
19 function GetPointInScreen(e, x, y) {
20 var point = e.getBoundingClientRect();
21 x += point.left;
22 y += point.top;
23 if (self != top) {
24 return window.parent.GetPointInScreen(window.parent.$("[name='myIframe']")[0], x, y);
25 }
26 return { x: x, y: y };
27 }
28
29 $("body").on("click", ".ShowMaxImg,[ShowMaxImg]", function () {
30 var src = "";
31 if ($(this).attr("ShowMaxImg") != undefined) {
32 src = $(this).attr("ShowMaxImg");
33 }
34 else {
35 src = $(this).attr("src");
36 }
37 if (src == "" || src == undefined) {
38 return;
39 }
40 var point = GetPointInScreen(this, 0, 0);
41 var w = $(this).width();
42 var h = $(this).height();
43 ShowMaxImg(src, point.y, point.x, w, h);
44 });
4、cs代码
1 #ShowMaxImgBox {
2 position: fixed;
3 width: 100vw;
4 height: 100vh;
5 display: flex !important;
6 background-color: rgba(0,0,0,0.6);
7 /*实现垂直居中*/
8 align-items: center !important;
9 /*实现水平居中*/
10 justify-content: center !important;
11 text-align: justify !important;
12 text-decoration: none;
13 -moz-user-select: none;
14 -webkit-user-select: none;
15 -ms-user-select: none;
16 user-select: none;
17 left: 0;
18 top: 0;
19 z-index: 9999;
20 }
21
22 #ShowMaxImgBox .ShowMaxImgBg {
23 z-index: -1;
24 position: absolute;
25 background-repeat: no-repeat;
26 background-position: center;
27 background-size: contain;
28 }
29
30 #ShowMaxImgBox .ShowMaxImgClose {
31 position: absolute;
32 width: 30px;
33 height: 30px;
34 right: 20px !important;
35 top: 20px !important;
36 z-index: 99;
37 }
38
39 #ShowMaxImgBox .ShowMaxImgClose i {
40 font-size: 20px;
41 }
42
43 #ShowMaxImgBox .ShowMaxImgBg p {
44 color: white;
45 position: absolute;
46 bottom: 10px;
47 text-align: center;
48 width: 100%;
49 height: 30px;
50 line-height: 30px;
51 }
52
53 [upload-showmaximg], [ShowMaxImg], .ShowMaxImg {
54 cursor: zoom-in !important;
55 }
56
57 #ShowMaxImgBox .ShowMaxImgBg:hover, #ShowMaxImgBox .ShowMaxImgClose:hover {
58 cursor: zoom-out !important;
59 }
jquery自定义弹层显示大图(兼容多层iframe)的更多相关文章
- CSS3/jQuery自定义弹出窗口
简单演示一下,精简了演示效果和css样式文件,更利于在项目中的实际应用 引入style.css index.js <!DOCTYPE HTML PUBLIC "-//W3C//DT ...
- Jquery 点击图片在弹出层显示大图
http://blog.csdn.net/wongwaidah/article/details/28432427(案例链接出处,本人只是转载收藏) <html> <head> ...
- jQuery Layer 弹层组件
layer是一款近年来口碑非常不错的web弹层组件,她具备全方位的解决方案,致力于服务各个水平段的开发人员,您的页面会轻松地拥有丰富友好的操作体验. 在与同类组件的比较中,layer总是能轻易获胜.她 ...
- 基于Vue.js PC桌面端弹出框组件|vue自定义弹层组件|vue模态框
vue.js构建的轻量级PC网页端交互式弹层组件VLayer. 前段时间有分享过一个vue移动端弹窗组件,今天给大家分享一个最近开发的vue pc端弹出层组件. VLayer 一款集Alert.Dia ...
- [转]Jquery 点击图片在弹出层显示大图
这个还行不需要别的包! https://www.cnblogs.com/antis/p/7053991.html
- JQuery - 点击图片显示大图
效果: 目录结构: 代码: <%@ Page Language="C#" AutoEventWireup="true" CodeFile="De ...
- apicloud实现各种自定义弹层组件
- jQuery 鼠标移入图片 显示大图并跟随鼠标移动
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8&quo ...
- 解决: 移动端经mouseover显示出的弹层中链接点击问题
通常我们会遇到这样的需求,导航菜单在鼠标划过的时候显示自定义弹层,在弹层中有一些链接需要点击后跳转或者其他一些事件.比如: $(".menu li").on("mouse ...
随机推荐
- Vue3实战系列:结合 Ant-Design-of-Vue 实践 Composition API
Vue 3 出来之后,很多人有如下想法,"又要学新东西啦"."我学不动了"等等. 但是事物总有它的两面性,前端知识更新的很快,利好勤奋好学的同学.计算机行业的迭 ...
- java的各种集合为什么不安全(List、Set、Map)以及代替方案
我们已经知道多线程下会有各种不安全的问题,都知道并发的基本解决方案,这里对出现错误的情况进行一个实际模拟,以此能够联想到具体的生产环境中. 一.List 的不安全 1.1 问题 看一段代码: publ ...
- 编程代码 | C++/C输出阳历万年历—精美日历制作
前言:本文章向大家介绍如何用C语言代码实现万年历使用实例.应用技巧.基本知识点总结和需要注意事项,具有一定的参考价值,需要的朋友可以参考一下. void输出万年历(int年, int月, int日 ...
- linux(centos8):查看操作系统的当前版本(os/kernel/bash)
一,查看redhat系操作系统的版本: 适用于centos/fedora/rhel等 [root@centos8 ~]# cat /etc/redhat-release CentOS Linux re ...
- 洛谷 P6602 数轴
时光倒流+暴力+尺取 第一次看到这题,是在神子杏的课堂上 这就是一个裸的双指针,洛咕上多倍经验的题太多了. --神子杏 那好,我们就用双指针来考虑这道题. 首先可以发现 答案区间$ (l,r) $ 一 ...
- 通过命令行上传ipa到appstore
搞持续集成自动化打包上传到appstore遇到这个问题,记录一下. 其实主要就一条到命令: xcrun altool --upload-app -f xxxx.ipa -u "yanqizh ...
- 深入理解Java的抽象类和接口
对于面向对象来说,抽象是其重要特征之一.对于之中的抽象类和接口,两者有很多相似的地方,又有两者之间区别的地方. 用几个简单的例子让你快速的理解两者之间的概念和区别 鸣谢 一.抽象类 在了解抽象类之前, ...
- Vue +WebSocket + WaveSurferJS 实现H5聊天对话交互
引言 在与实现了语音合成.语义分析.机器翻译等算法的后端交互时,页面可以设计成更为人性化.亲切的方式.我们采用类似于聊天对话的实现,效果如下: 智能客服(输入文本,返回引擎处理后的文本结果) 语音合成 ...
- 关于设置Vscode缩进,保存代码任然缩进无效解决方式
在Vscode按F1,运行命令,输入Formatter config 把内容更改为以下代码 { "onSave": true, "javascript": { ...
- Zotero导入Markdown here插件
1. 下载Markdown Here源码包 网址:https://github.com/adam-p/markdown-here 2. 创建.xpi后缀文件 将文件夹 中的这几个文件放入同一个文件夹中 ...