欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  IT编程

jquery实现可拖拽弹出层特效

程序员文章站 2023-11-08 10:45:04
功能很简单,却非常的实用,代码更加的简洁,这里就不多废话了 代码如下:

功能很简单,却非常的实用,代码更加的简洁,这里就不多废话了

代码如下:


<!doctype html>
<html xmlns="https://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="content-type" content="text/html; charset=utf-8" />
<title></title>
<style type="text/css">
*
{
margin: 0px;
padding: 0px;
}
.dragbox
{
width: 400px;
height: 200px;
position: absolute;
top: 40%;
left: 40%;
background: #e8e8e8;
z-index: 8001;
}
.dragbox > p
{
height: 30px;
cursor: move;
background: #00ff21;
position: relative;
}

 

.ui-mask
{
width: 100%;
height: 100%;
background: #000;
position: absolute;
top: 0px;
z-index: 8000;
opacity: 0.4;
filter: alpha(opacity=40);
}
</style>
<script src="framework/base/jquery-1.8.3.min.js"></script>
<script type="text/javascript"></script>
<script type="text/javascript">
$(function () {
var mouseoffx = 0;
var mouseoffy = 0;
var isdrag = false;
$(".dragbox p:eq(0)").unbind(".click").on("mousedown", function (ev) {
mouseoffx = ev.clientx - $(".dragbox p:eq(0)").offset().left;
mouseoffy = ev.clienty - $(".dragbox p:eq(0)").offset().top;
isdrag = true;
})
$(document).unbind(".click").on("mousemove", function (ev) {
var moursex = ev.clientx, moursey = ev.clienty;
var movex = 0, movey = 0;
if (isdrag === true) {
movex = moursex - mouseoffx;
movey = moursey - mouseoffy;
var maxx = $(window).outerwidth(false) - $(".dragbox").outerwidth(false);
var maxy = $(window).outerheight(false) - $(".dragbox").outerheight(false);
movex = math.min(maxx, math.max(0, movex));
movey = math.min(maxy, math.max(0, movey));
$(".dragbox").css({ "left": movex, "top": movey });
}
});
$(document).unbind(".click").on("mouseup", function () {
isdrag = false;
});
});
</script>
</head>
<body>
test
<p class="ui-mask" id="mask" onselectstart="return false"></p>
<p class="dragbox">
<p>
</p>
</p>
</body>
</html>