


this effect is used very frequently, and people often ask me this question, so i want to write it into an article. next time someone asks, just throw out the url of this article. this effect is very simple, so i won’t explain it too much. you will understand it if you look at the code comments. below is the entire code, you can copy it into html and run it.
<!DOCTYPE html> <style> #mask { position:fixed;width:100%; top:0px;left:0px; _position:absolute; _top:expression(documentElement.scrollTop); background:rgba(0,0,0,0.5); background:transparent\9; filter:progid:DXImageTransform.Microsoft.Gradient( startColorStr=#80000000,endColorStr=#80000000 ); display:none; } #mask_td {text-align:center;} </style> <img src="/static/imghwm/default1.png" data-src="http://web-tinker.com/images/TheMagicConch.jpg?x-oss-process=image/resize,p_40" class="lazy" style="max-width:90%" id="img" /> <table id="mask"><tr><td id="mask_td"></td></tr></table> <script> //判断浏览器 var isIE=navigator.userAgent.match(/MSIE (\d)/i); isIE=isIE?isIE[1]:isIE; //声明变量 var img,mask; //获取元素 img=document.getElementById("img"); mask=document.getElementById("mask"); mask.td=document.getElementById("mask_td"); //计算mask的大小 mask.setSize=function(){ //获取文档可见区域宽度并设置到mask上 var de=document.documentElement; mask.style.width=de.clientWidth+"px" mask.style.height=de.clientHeight+"px"; }; //添加show方法 mask.show=function(){ //隐藏页面的滚动条 document[ isIE<9?"documentElement":"body" ].style.overflow="hidden"; //计算mask的大小 mask.setSize(); //显示 mask.style.display=isIE==6?"block":"table"; }; //添加hide方法 mask.hide=function(){ //显示页面滚动条 document[ isIE<9?"documentElement":"body" ].style.overflow=""; //清空里面的内容 mask.td.innerHTML=""; //隐藏 mask.style.display="none"; }; //添加append方法 mask.append=function(e){ //在mask的TD里面添加内容哦你 mask.td.appendChild(e); }; //点击mask关闭 mask.onclick=function(e){ //判断事件来源,如果是空白区域被点击了就关闭mask e=e||event; (e.target||e.srcElement)==mask.td&&mask.hide(); }; //窗体大小改变时也改变mask的大小 window.onresize=function(){ mask.setSize(); }; //点击图片的事件 img.onclick=function(){ //创建一个图片对象 var o=new Image; //设置图片的地址 o.src=img.src; //在mask内添加内容 mask.append(o); //显示mask mask.show(); }; </script>
there is no difficulty in this effect. perhaps the most difficult thing is to achieve translucency. both css3's opacity and ie's alpha can achieve translucency, but that is the translucency of the entire element. using that method means that the child element is also made translucent, so we have to set transparency to the background, not the entire element. in css3, rgba can be used directly to set it. there is no such method in ie, but you can use a gradient filter to replace it, because the gradient filter also supports transparency. also, in ie9, it is compatible with both css3 transparency and filter transparency. if both are used, the transparency of the page will be incorrect. so we blocked one of the transparency effects in ie9.
another problem is that it is compatible with ie6. ie6 does not support fixed, so we need to use absolute and dynamically set top to be compatible with it. then there is the problem of mask size calculation. there is also a browser difference in this. in fact, the browser difference in this effect is quite big, but they are all small problems and you will understand that there is no need for a long explanation.

去掉重复并排序的方法:1、使用“Array.from(new Set(arr))”或者“[…new Set(arr)]”语句,去掉数组中的重复元素,返回去重后的新数组;2、利用sort()对去重数组进行排序,语法“去重数组.sort()”。

本篇文章给大家带来了关于JavaScript的相关知识,其中主要介绍了关于Symbol类型、隐藏属性及全局注册表的相关问题,包括了Symbol类型的描述、Symbol不会隐式转字符串等问题,下面一起来看一下,希望对大家有帮助。

怎么制作文字轮播与图片轮播?大家第一想到的是不是利用js,其实利用纯CSS也能实现文字轮播与图片轮播,下面来看看实现方法,希望对大家有所帮助!

本篇文章给大家带来了关于JavaScript的相关知识,其中主要介绍了关于对象的构造函数和new操作符,构造函数是所有对象的成员方法中,最早被调用的那个,下面一起来看一下吧,希望对大家有帮助。

方法:1、利用“点击元素对象.unbind("click");”方法,该方法可以移除被选元素的事件处理程序;2、利用“点击元素对象.off("click");”方法,该方法可以移除通过on()方法添加的事件处理程序。

本篇文章给大家带来了关于JavaScript的相关知识,其中主要介绍了关于面向对象的相关问题,包括了属性描述符、数据描述符、存取描述符等等内容,下面一起来看一下,希望对大家有帮助。

foreach不是es6的方法。foreach是es3中一个遍历数组的方法,可以调用数组的每个元素,并将元素传给回调函数进行处理,语法“array.forEach(function(当前元素,索引,数组){...})”;该方法不处理空数组。

本篇文章给大家带来了关于JavaScript的相关知识,其中主要介绍了关于BOM操作的相关问题,包括了window对象的常见事件、JavaScript执行机制等等相关内容,下面一起来看一下,希望对大家有帮助。


Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

Dreamweaver CS6
Visual web development tools

Notepad++7.3.1
Easy-to-use and free code editor

Safe Exam Browser
Safe Exam Browser is a secure browser environment for taking online exams securely. This software turns any computer into a secure workstation. It controls access to any utility and prevents students from using unauthorized resources.

SublimeText3 English version
Recommended: Win version, supports code prompts!

ZendStudio 13.5.1 Mac
Powerful PHP integrated development environment