javascript代码实例教程-jquery实现可拖拽弹出层特效

发布时间:2018-12-29 发布网站:脚本宝典
脚本宝典收集整理的这篇文章主要介绍了javascript代码实例教程-jquery实现可拖拽弹出层特效脚本宝典觉得挺不错的,现在分享给大家,也给大家做个参考。
小宝典致力于为广大程序猿(媛)提供高品质的代码服务,请大家多多光顾小站,小宝典在此谢过。

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

代码如下:


<!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;
}

&nbsp;

.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>

 

觉得可用,就经常来吧! 脚本宝典 欢迎评论哦! js脚本,巧夺天工,精雕玉琢。小宝典献丑了!

脚本宝典总结

以上是脚本宝典为你收集整理的javascript代码实例教程-jquery实现可拖拽弹出层特效全部内容,希望文章能够帮你解决javascript代码实例教程-jquery实现可拖拽弹出层特效所遇到的问题。

如果觉得脚本宝典网站内容还不错,欢迎将脚本宝典推荐好友。

本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。