87,907
社区成员
发帖
与我相关
我的任务
分享
/*自主弹窗*/
.popdiv{
width:500px;
height:200px;
position: absolute;
display: none;
left:0;top:0
}
/*必须设一个宽高和padding,border,兼容垃圾ie11*/
.popdiv_content{
padding:0px;
border-width: 2px;
border: 2px solid #000; background-color: #EDEDED;font-size: 14px;
position: relative;
width:200px;height:100px;
}
.popdiv_head{
color: #1F1F1F;font-size:15px;font-weight: bold;
height:30px;line-height: 30px;background-color: #69E7ED;cursor:move;border-bottom:#59C5CA solid 1px ;
}
.popdiv_title{margin-left: 10px;float:left;line-height: 15px;}
.close_btn {
color: #fff;
float: right;
margin-right: 5px;
width: 40px;
height: 20px;
line-height: 20px;
background-color: #3f9cff;
text-align: center;
font-size: 12px;
cursor: pointer
}
.popdiv_maintext{padding:5px;overflow:auto;}
(function($){
/*$(selector).Ymoving() 全浏览器兼容可移动插件
*author yukon12345
*@parame MIX handler接受选择器或jquery对象。默认为自己的jquery对象包装
*@param JSON appearance 点击后变成的外观
*@param Function fx 动态效果函数
*@param Function overEvent 结束后执行函数
*@param JSON oldCss 原外观
*@desktopMode Boolean 桌面窗口模拟,true的话会点击置顶
*/
$.fn.Ymoving=function(opts){
if(typeof console === "undefined") { var console = { log: function (logMsg) { } };}
var vars= $.extend({
handler:null,
appearance:{"opacity":0.7},
fx:null,
overEvent:function(){},
oldCss:{},
desktopMode:true
},opts);
return this.each(function(){
//判断handler,为空则是自己,非空为选择器或jquery对象
var handler;
//maxIndex为当前窗口最大index
window.maxIndex=window.maxIndex?window.maxIndex:1000;
if(typeof vars.handler=='undefined'||vars.handler==null||vars.handler=="")
{handler=$(this)}
else
{ typeof vars.handler=='string'? handler=$(vars.handler,this):handler=vars.handler;}
//获取原有样式
// console.log("原始index:" +$(this).css("z-index"));
for(var key in vars.appearance){
vars.oldCss[key]= $(this).css(key);
}
// console.log( vars.oldCss);
// console.log(vars.appearance);
//被移动的对象
var whole=this;
//为了兼容2b的ie6变完全透明加上这句话
$(whole).children(":not(.popdiv_back)").css("opacity",1)
var relativeX,relativeY;
handler.bind("mousedown",function(event){
vars.desktopMode?window.maxIndex++:0;
$(whole).css(vars.appearance);
vars.desktopMode?$(whole).css("z-index",window.maxIndex):0;
relativeX=event.pageX-parseInt($(whole).css("left"));
relativeY=event.pageY-parseInt($(whole).css("top"));
// console.log("可执行设置坐标"+relativeX+","+relativeY)
//alert("可执行设置坐标"+relativeX+","+relativeY)
$(document).bind("mousemove",function(event){
$(whole).css("top",event.pageY-relativeY);
$(whole).css("left",event.pageX-relativeX);
// console.log("可执行设置坐标" +$(whole).css("top"));
})
});
$(document).bind("mouseup",function(event){
vars.overEvent();
$(document).unbind("mousemove");
$(whole).css(vars.oldCss);
//console.log($(whole).attr("id")+"回复后的index:" +$(whole).css("z-index"))
})
})
};
})(jQuery);
<!DOCTYPE html>
<html>
<head> <meta content="text/html" charset="utf-8">
<title></title>
<link href="../web_back/css/core.css" rel="stylesheet" type="text/css">
<script type="text/javascript" src="../js/jquery-1.2.6.min.js"></script>
<script type="text/javascript" src="../js/jquery.YukonPlugins.js"></script>
<script type="text/javascript" >
$(function(){
$("#t1").Ymoving({"handler":".popdiv_head"})
$("#notice").Ymoving({"handler":".popdiv_head"})
})
</script>
</head>
<body>
<div class="popdiv" style="display:block;position: absolute" id="t1"><div class="popdiv_back"></div><div class="popdiv_content"><div class="popdiv_head"><p class="popdiv_title">点我呀1</p><div class="close_btn">X</div></div>111大是大非的是法国岁的法国啊东方化工啊的风格阿桑的歌啊<button id="show2">点我</button></div></div>
<div class="popdiv" style="display:block;position: absolute" id="notice"><div class="popdiv_back"></div><div class="popdiv_content"><div class="popdiv_head"><p class="popdiv_title">提示信息</p><div class="close_btn">X</div></div><div class="popdiv_maintext"></div></div></div>
<div style="height:250px"></div>
<div style="height:250px;position: relative;z-index: 10;">
<select><option>测试哈哈哈的</option><option>测试哈哈哈</option></select>
<button id="show">点我</button>
</div>
<div style="height:2500px"></div>
</body>
</html>