如果点击iframe中的image显示整个页面的遮罩层,可参考如下:

http://blog.csdn.net/shiaijuan1/article/details/70160714

具体思路就是,顶层添加dom对象,用来显示信息,默认隐藏,需要时在iframe中调用,宽高设置为100%。

实现如下:

   //遮罩层
.showmask {
position: fixed;//position设置为fixed或者absolute或者relative,z-index才生效,且z-index值越大越显示到顶层
z-index:;//fixed固定定位,相对于浏览器窗口
width: 100%;//relative相对定位,相对于其正常位置进行定位,比如left:20px,相对于其正常位置向左偏移20个像素
height: 100%;
background-color: silver;
top: 0px;
left: 0px;
opacity: 0.5;//遮罩透明度
} .showmasklayer {
position: absolute;//绝对定位,相对于该元素之外的第一个父元素进行定位
z-index:;
top: 0px;
left: 0px;
min-width: 100%;
min-height: 100%;
display: flex;//多列布局
justify-content: center;//设置元素在主轴(横轴)上的对其方式
align-items: center;//当前行侧轴(纵轴)方向上的对齐方式
}
//关闭按钮
.showmaskclose {
background-color: red;
color: white;
border: 2px solid gray;
position: fixed;
z-index:;
top: 0px;
right: 0px;
cursor: pointer;
height: 30px;
width: 30px;
font-size: large;
font-weight: bold;
text-align: center;
display: flex;
justify-content: center;
align-items: center;
}

这儿调整一下,为了解决,部分图片像素过大,浏览器无法展示全部,又没有加入拖动及滚动条等:

       .showmask {
position: fixed;
z-index:;
width: 100%;
height: 100%;
background-color: silver;
top: 0px;
left: 0px;
opacity: 0.5;
} .showmasklayer {
position: absolute;
z-index:;
top: 0px;
left: 0px;
/*min-width: 100%; 这里默认显示100%,不能超过100%
min-height: 100%;*/
width: 100%;
height: 100%;
display: flex;
justify-content: center;
align-items: center;
} .showmasklayer img {
max-width: 100%;/*图片最大宽高都是100%*/
max-height: 100%;
} .showmaskclose {
background-color: red;
color: white;
border: 2px solid gray;
position: fixed;
z-index:;
top: 0px;
right: 0px;
cursor: pointer;
height: 30px;
width: 30px;
font-size: large;
font-weight: bold;
text-align: center;
display: flex;
justify-content: center;
align-items: center;
}

iframe中调用如下:

 $(function () {
$("#image").on("click", function () {
//判断是否已经添加过遮罩层dom
if ($(".showmaskclose", window.top.document).length == 0) {
//附加遮罩层dom
$("body", window.top.document).append("<div class='showmaskclose'>×</div>").append("<div class='showmask'></div>").append("<div class='showmasklayer'></div>")
          //这儿双击遮罩showmask/showmasklayer时候,会导致showmasklayer图片成选中状态,这儿可以调整为如下,参照:www.w3cui.com?p=141
          //.append("<div class='showmasklayer' unselectable='on' style='-moz-user-select:none;' onselectstart='return false;'></div>");
//附加后绑定事件
$(".showmaskclose", window.top.document).on("click", function () { htsHide(); })
$(".showmask", window.top.document).on("dblclick", function () { htsHide(); })
$(".showmasklayer", window.top.document).on("dblclick", function () { htsHide(); })
//添加图片
$(".showmasklayer", window.top.document).append("<img src='" + this.src + "' />")
}
else {
//遮罩层dom显示
$(".showmaskclose", window.top.document).show();//可通过css设置display为none和block控制显示和隐藏
$(".showmask", window.top.document).show();
$(".showmasklayer", window.top.document).show();
//切换图片
$(".showmasklayer > img", window.top.document).attr('src', this.src);
}
});
});
function htsHide() {
//遮罩层隐藏
$(".showmask", window.top.document).hide();
$(".showmaskclose", window.top.document).hide();
$(".showmasklayer", window.top.document).hide();
}

以上的js在双击showmask关闭时,重新打开,时而会出现一个类似于showmask选中状态的东西,体验不好,可以每次关闭后移除,下次点击时添加,如下:

$(function () {
$("#image").on("click", function () {
//添加遮罩层
$("body", window.top.document).append("<div class='showmaskclose'>×</div>").append("<div class='showmask'></div>").append("<div class='showmasklayer'></div>")
//绑定遮罩层事件
$(".showmaskclose", window.top.document).on("click", function () { htsHide(); })
$(".showmask", window.top.document).on("dblclick", function () { htsHide(); })
$(".showmasklayer", window.top.document).on("dblclick", function () { htsHide(); })
$(".showmasklayer", window.top.document).append("<img src='" + this.src + "' />")
});
});
function htsHide() {
//移除遮罩层
$(".showmaskclose", window.top.document).remove();
$(".showmask", window.top.document).remove();
$(".showmasklayer", window.top.document).remove();
}

呵呵,升级一下,加入图像的旋转功能,主要是通过css样式调整实现:

css:

.showmask {
position: fixed;
z-index:;
width: 100%;
height: 100%;
background-color: silver;
top: 0px;
left: 0px;
opacity: 0.5;
} .showmasklayer {
position: absolute;
z-index:;
top: 0px;
left: 0px;
width: 100%;
height: 100%;
display: flex;
justify-content: center;
align-items: center;
} .showmasklayer img {
max-width: 100%;
max-height: 100%;
} .showmaskrotate {/*实现旋转的按钮*/
background-color: Highlight;
color: white;
border: 2px solid gray;
position: fixed;
z-index:;
top: 0px;
right: 40px;
cursor: pointer;
height: 30px;
width: 30px;
font-size: large;
font-weight: bold;
text-align: center;
display: flex;
justify-content: center;
align-items: center;
} .showmaskclose {
background-color: red;
color: white;
border: 2px solid gray;
position: fixed;
z-index:;
top: 0px;
right: 0px;
cursor: pointer;
height: 30px;
width: 30px;
font-size: large;
font-weight: bold;
text-align: center;
display: flex;
justify-content: center;
align-items: center;
}

js,rotate实现:

/**
* jquery-rotate v0.1.0
* Very lightweight jquery rotate plugin using CSS 3 Transformation
* https://github.com/schickling/jquery-rotate*/
(function ($) { $.fn.extend({
rotate: function (deg) { // cache dom element
var $this = $(this); // make deg random if not set
if (deg === null) {
deg = Math.floor(Math.random() * 359);
} // rotate dom element
$this.css({
'-webkit-transform': 'rotate(' + deg + 'deg)',
'-moz-transform': 'rotate(' + deg + 'deg)',
'-ms-transform': 'rotate(' + deg + 'deg)',
'-o-transform': 'rotate(' + deg + 'deg)',
'transform': 'rotate(' + deg + 'deg)'
}); // make chainable
return $this;
}
}); })(jQuery);

js,调用img遮罩:

    function htsHide() {
$(".showmaskclose", window.top.document).remove();
$(".showmaskrotate", window.top.document).remove();
$(".showmask", window.top.document).remove();
$(".showmasklayer", window.top.document).remove();
}
oper = {
View: function (imagepath) {
$("body", window.top.document).append("<div class='showmaskclose'>×</div><div class='showmaskrotate'>⌒</div>").append("<div class='showmask'></div>").append("<div class='showmasklayer'></div>")
var tIndex = 0;//控制旋转次数
$(".showmaskclose", window.top.document).on("click", function () { htsHide(); })
$(".showmaskrotate", window.top.document).on("click", function () { $('.showmasklayer > img', window.top.document).rotate(-90 * ++tIndex); })//实现旋转功能,每次逆时针旋转90度
$(".showmask", window.top.document).on("dblclick", function () { htsHide(); })
$(".showmasklayer", window.top.document).on("dblclick", function () { htsHide(); })
$(".showmasklayer", window.top.document).append("<img src='" + imagepath + "' style='max-height:100%;max-width:100%;'/>")
}
}

jquery 遮罩层显示img的更多相关文章

  1. jQuery遮罩层插件

    在网页上常常遇到须要等待非常久的操作,比方导出报表等.为了预防用户点击其它操作或者多次点击同个功能,须要用遮罩层把页面或者操作区盖住.防止用户进行下一步操作.同一时候能够提高界面友好度,让用户知道操作 ...

  2. jQuery遮罩层登录对话框

    用户登录是许多网站必备的功能.有一种方式就是不管在网站的哪个页面,点击登录按钮就会弹出一个遮罩层,显示用户登录的对话框.这用方式比较灵活方便.而现在扫描二维码登录的方式也是很常见,例如QQ.微信.百度 ...

  3. jQuery遮罩层的实现

    遮罩层其实就是一个占据整个页面的半透明效果的页面元素,一般用div实现.页面中实现遮罩层,无非就是为了让用户只能操作弹出窗口的内容,而不允许操作弹出窗口外的内容. 在实现时,我使用了两个div,一个遮 ...

  4. JS+CSS简单实现DIV遮罩层显示隐藏【转藏】

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/ ...

  5. JS+CSS简单实现DIV遮罩层显示隐藏

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/ ...

  6. z-index设置后导致遮罩层显示跳动问题

    如图,1,3为top,bottom div,2为iscroll,4为遮罩层,如果1设置z-index后,不设置遮挡不住2,遮罩层4弹出会卡顿,既不设置z-index,又能遮挡iscroll的办法是在h ...

  7. jquery遮罩层

    (function () { //遮罩层实现 zhe zhao ceng kexb 2016.2.24 $.extend($.fn, { mask: function (msg, maskDivCla ...

  8. jQuery遮罩层效果

    <!DOCTYPE html><html lang="en"><head> <meta charset="UTF-8" ...

  9. 页面用一个遮罩层显示加载,加载完后隐藏该div

    <div id="background" class="background" style="display: none; "> ...

随机推荐

  1. 适合初学者的嵌入式Linux计划

    俗话说万事开头难,刚开始的时候,你是否根本就不知如何开始,上网查资料被一堆堆新名词搞的找不到北,去图书馆看书也是找不到方向?又是arm,又是linux,又是uboot头都大了,不知道自己究竟从哪里开始 ...

  2. 蓝牙核心技术概述(四):蓝牙协议规范(HCI、L2CAP、SDP、RFOCMM)(转载)

    一.主机控制接口协议  HCI 蓝牙主机-主机控模型 蓝牙软件协议栈堆的数据传输过程: 1.蓝牙控制器接口数据分组:指令分组.事件分组.数据分组(1).指令分组 如:Accpet Connection ...

  3. forward_list

    一.特性 单向链表,只支持单向顺序访问(不支持快速随机访问),是C++11标准新增的类型 可类比于数据结构——单(向)链表 1. 没有size操作 forward_list为了追求性能,省去了size ...

  4. ZOJ 1913 J-Eucild's Game

    https://vjudge.net/contest/67836#problem/J Two players, Stan and Ollie, play, starting with two natu ...

  5. cURL和file_get_contents实现模拟post请求

    以前面试时候,面试官问过我后端有没有跨域问题,但是不敢肯定,现在可以肯定的说没有. 不文用php的cURL和file_get_contents方法分别实现后端跨域.本文场景也是在tp5下实现的. 一, ...

  6. DEDE去掉会员登录及注册验证码的方法

    1.登录打开member/index_do.php 删除245-250行,即: if(strtolower($vdcode)!=$svali || $svali=='') { ResetVdValue ...

  7. Oracle中预定义角色有哪些?

    1. CONNECT 2. RESOURCE 3. DBA 4. EXP_FULL_DATABASE 5. IMP_FULL_DATABASE 6. DELETE_CATALOG_ROLE 7. EX ...

  8. Maven 生命周期 和插件

    1.3 生命周期1.3.1 什么是生命周期? Maven生命周期就是为了对所有的构建过程进行抽象和统一.包括项目清理.初始化.编译.打包.测试.部署等几乎所有构建步骤. 生命周期可以理解为构建工程的步 ...

  9. 运行jar

    将Spring Boot 应用打包成jar, java -jar **.jar运行, 如果需要设置运行参数 java -jar **.jar --server.port=9080

  10. Hadoop——HDFS的构架

    在使用一个工具之前,应该先对它的机制.组成等有深入的了解,以后才会更好的使用它.下面来介绍一下什么是HDFS,以及他的构架是什么样的. 1.什么是HDFS? Hadoop主要是用于进行大数据处理,那么 ...