[snippet] show dialog

/*! Copyright Cdialog
* version 1.0
* liscense MIT
*/

var Cdialog = {
		showMask: true,			//show mask
		isScroll:false,			//auto detect scroll
		zIndex: 1000,				//z-index of the mask
		scrollBar: 0,				//auto calc scrollbar width
		init: function(){
			
				$.ajaxSetup ({cache: false });	//disable ajax cache
				$(window).scrollTop(100);if($(window).scrollTop()){this.isScroll=true;$(window).scrollTop(0);}		//detect scroll
				
				if(this.isScroll){			//calc scrollbar width
					const scrollDiv = document.createElement("div");
					$(scrollDiv).width(100).height(100).css({"overflow-y":"scroll","position":"absolute","top":"-100px"});
					$("body").append(scrollDiv);
					this.scrollBar = 100-scrollDiv.clientWidth;
					$(scrollDiv).remove();
				}
				
				$("<div id='Cmodule'></div>").load("/common/common.html",function(e){$("body").append($(this));$(".Cclose").on("click",function(){$(".Cmask").trigger("click");$(this).parent().slideUp("fast");});});		//preload module
				},
		show: function(name){		//show module via element id
			var dialog = $("#"+name);
			if(name&&dialog.length){
				if(this.showMask){
					$(window).scrollLeft(0);	//reset scrollLeft value
					var mask = $("<div class=\"Cmask\"></div>");
							mask.css({"background":"#000","opacity":"0.5","filter":"alpha(opacity=50)","zIndex":this.zIndex,"position":"absolute","top":"0","left":"0"})
									.height("100%").width("100%")
									.appendTo($("body")).show().click(function(){
										$(this).fadeOut("fast",function(){$(this).remove();$("html").css("padding-right","0");bar.remove();$("body").css("overflow","auto");});
										dialog.slideUp("fast");
									});
									
					if(this.isScroll){		//fix content offset when isScroll, refer to Qzone
						$("html").css({"padding-right":this.scrollBar+"px"});
						bar = $("<div style='position:fixed;right:0;width:"+this.scrollBar+"px;height:100%;top:0;background:url(bg.jpg) repeat;z-index:"+(this.zIndex-1)+";'></div>");
						$("body").css("overflow","hidden").append(bar);
					}
					$("#Cmodule").width(dialog.width()).height(dialog.height()).css({"zIndex":this.zIndex+1,"position":this.showMask?"absolute":"fixed","top":"50%","left":"50%","marginTop":-dialog.height()/2+"px","marginLeft":-dialog.width()/2-this.scrollBar/2+"px"})
					dialog.show();
				}	
			}
		}
	}
$(function(){Cdialog.init()});

 

 

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>index</title>
<script type="text/javascript" src="jquery-1.9.1.min.js"></script>
<script type="text/javascript" src="js.js"></script>
<link rel="stylesheet" type="text/css" href="css.css" />
<style>
body{
	margin:0;
	padding:0;
	height:1500px;
	width:1000px;
	text-align:center;}
html{
	background:#FFF;}
</style>
</head>

<body>

<button οnclick="Cdialog.show('login');">Click</button>
</body>
</html>

 

转载于:https://www.cnblogs.com/ipup/p/3791385.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值