js 遮蔽层+拖拽


//css样式
.over_layer{
background-color: black;
display: none;
height: 100%;
left: 0;
opacity: 0.5;
position: absolute;
top: 0;
width: 100%;
z-index: 1001;
}
//遮蔽层
<div id="fade" class="over_layer" style="background:black; filter: alpha(opacity=50); opacity: 0.5; -moz-opacity:0.5;"></div>

//js
function getScrollTop(){
var scrollTop = 0;
if(document.documentElement && document.documentElement.scrollTop){
scrollTop = document.documentElement.scrollTop;
}else if(document.body){
scrollTop = document.body.scrollTop;
}
return scrollTop;
}


var wcontentflag = false,wcontentX=null,wcontentY=null,offsetWidth=null,offsetHeigth=null,isaddoffset=false;
function showModel(showId,isdrop){
$("#fade").css("height",window.screen.availHeight+parseFloat(getScrollTop()));
$("#fade").css("width",window.screen.availWidth);
try{
$("#"+showId).css("z-index",1005);
$("#"+showId).css("position","absolute");
$("#"+showId).css("top",20+parseFloat(getScrollTop()));
$("#"+showId).css("left",window.screen.availWidth/2-parseFloat($("#"+showId).css("width"))/2);
}catch(e){}

if(typeof(isdrop)=='undefined' || isdrop == true){
$("#"+showId).bind("mousedown",function(e){
if(!wcontentflag){
wcontentflag = true;
wcontentX = e.pageX;
wcontentY = e.pageY;
offsetWidth = e.pageX - parseFloat($(this).css("left"));
offsetHeight = e.pageY - parseFloat($(this).css("top"));
$(this).css("cursor","pointer");
}
});

$("body").bind("mousemove",function(e){
if(wcontentflag){
var nowPageX = e.pageX;
var nowPageY = e.pageY;
var nowObjX = parseFloat($("#"+showId).css("left"));
var nowObjY = parseFloat($("#"+showId).css("top"));

nowObjX = parseFloat(nowObjX) + (nowPageX-nowObjX);
nowObjY = parseFloat(nowObjY) + (nowPageY-nowObjY);

nowObjX -= offsetWidth;
nowObjY -= offsetHeight;

$("#"+showId).css({left:nowObjX,top:nowObjY});
$("#"+showId).css({left:nowObjX,top:nowObjY});
}
});

$("body").bind("mouseup",function(e){
if(wcontentflag){
wcontentflag = false;
isaddoffset =false;
$("#"+showId).css("cursor","default");
}
});
}
showAndHidden(showId,'show');
showAndHidden('fade','show');
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值