自用蒙板控件

var Mask = (function(){
				//私有方法,外面无法访问
				var mask = document.createElement("div");
				mask.style.width="100%";
				mask.style.height="100%";
				mask.style.position="absolute";
				mask.style.left="0";
				mask.style.top="0";
				mask.style.opacity="0.5";
				mask.style.background="rgb(0, 0, 0)";
				mask.id="mask";
				var MaskFun = function(dom){
					
				}
				MaskFun.prototype.mask = function(dom){
					//浏览器窗口内部大小
					dom.show();
					var innerHeight = window.innerHeight,
					    innerWidth = window.innerWidth,
					    domWidth = dom[0].offsetWidth,
					    domHeight = dom[0].offsetHeight;
					$("body").append(mask);
					dom[0].style.left=(innerWidth -domWidth)/2 +"px";
					dom[0].style.top = (innerHeight - domHeight)/2 +"px";
				}
				MaskFun.prototype.unmask = function(dom){
					dom.hide();
					$("#mask").remove();
				}
				return MaskFun
			})();
<span style="color: rgb(34, 34, 34); font-family: Consolas, 'Lucida Console', monospace; white-space: pre-wrap;"><span style="white-space:pre">	</span>依赖jquery   </span>
var  jmask = new Mask();
mask是show蒙板,unmask是取消蒙板

 

©️2020 CSDN 皮肤主题: 大白 设计师:CSDN官方博客 返回首页