支持拖拽功能带最大化最小化窗口js特效

3个月前 (02-20 11:56)阅读71回复0
大陆
大陆
  • 管理员
  • 发消息
  • 注册排名1
  • 经验值4189
  • 级别管理员
  • 主题837
  • 回复2
楼主

带可拖动窗口功能的js特效代码分享,支持窗口最大化和最小化,带关闭按钮,经典实用窗口拖动网页特效。

<!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=gb2312" />
<title>支持拖拽功能带最大化最小化窗口_武鸣人</title>
<meta name="keywords" content="武鸣人网站,武鸣信息网,武鸣本地网,武鸣信息资源平台,减肥,健身,励志,励志语录,js特效,网页特效,www.wuming.ren">
<meta name="description" content="欢迎来到武鸣人信息资源平台,各种信息免费发布,资源共享合作共赢,分享互联网流行的励志语录经典短句,减肥健身健康小常识及打卡记录,收集各种js特效代码。">
<style type="text/css">
body,div,h2{margin:0;padding:0;}
body{background:url(/img/20240220_wuming_ren_15.jpg);font:12px/1.5 \5fae\8f6f\96c5\9ed1;color:#333;}
#www_wuming_ren{position:absolute;top:100px;left:100px;width:300px;height:160px;background:#e9e9e9;border:1px solid #444;border-radius:5px;box-shadow:0 1px 3px 2px #666;}
#www_wuming_ren .title{position:relative;height:27px;margin:5px;}
#www_wuming_ren .title h2{font-size:14px;height:27px;line-height:24px;border-bottom:1px solid #A1B4B0;}
#www_wuming_ren .title div{position:absolute;height:19px;top:2px;right:0;}
#www_wuming_ren .title a,a.open{float:left;width:21px;height:19px;display:block;margin-left:5px;background:url(/img/20240220_wuming_ren_13.png) no-repeat;}
a.open{position:absolute;top:10px;left:50%;margin-left:-10px;background-position:0 0;}
a.open:hover{background-position:0 -29px;}
#www_wuming_ren .title a.min{background-position:-29px 0;}
#www_wuming_ren .title a.min:hover{background-position:-29px -29px;}
#www_wuming_ren .title a.max{background-position:-60px 0;}
#www_wuming_ren .title a.max:hover{background-position:-60px -29px;}
#www_wuming_ren .title a.revert{background-position:-149px 0;display:none;}
#www_wuming_ren .title a.revert:hover{background-position:-149px -29px;}
#www_wuming_ren .title a.close{background-position:-89px 0;}
#www_wuming_ren .title a.close:hover{background-position:-89px -29px;}
#www_wuming_ren .content{overflow:auto;margin:0 5px;}
#www_wuming_ren .wuming_ren_8{position:absolute;width:14px;height:14px;right:0;bottom:0;overflow:hidden;cursor:nw-resize;background:url(/img/20240220_wuming_ren_14.png) no-repeat;}
#www_wuming_ren ._wuming__ren_2,#www_wuming_ren .wuming__3,#www_wuming_ren .wuming_4,#www_wuming_ren .wuming_ren_5,#www_wuming_ren .www_wuming__ren_6,#www_wuming_ren .www__wuming__ren_7,#www_wuming_ren .wuming_ren_9{position:absolute;background:#000;overflow:hidden;opacity:0;filter:alpha(opacity=0);}
#www_wuming_ren ._wuming__ren_2,#www_wuming_ren .wuming_4{top:0;width:5px;height:100%;cursor:w-resize;}
#www_wuming_ren .wuming_4{right:0;}
#www_wuming_ren .wuming__3,#www_wuming_ren .wuming_ren_5{width:100%;height:5px;cursor:n-resize;}
#www_wuming_ren .wuming__3{top:0;}
#www_wuming_ren .wuming_ren_5{bottom:0;}
#www_wuming_ren .www_wuming__ren_6,#www_wuming_ren .www__wuming__ren_7,#www_wuming_ren .wuming_ren_9{width:8px;height:8px;background:#FF0;}
#www_wuming_ren .www_wuming__ren_6{top:0;left:0;cursor:nw-resize;}
#www_wuming_ren .www__wuming__ren_7{top:0;right:0;cursor:ne-resize;}
#www_wuming_ren .wuming_ren_9{left:0;bottom:0;cursor:ne-resize;}
</style>
<script type="text/javascript">
/*-------------------------- +
  获取id, class, tagName
 +-------------------------- */
var get = {
byId: function(id) {
return typeof id === "string" ? document.getElementById(id) : id
},
byClass: function(sClass, oParent) {
var aClass = [];
var reClass = new RegExp("(^| )" + sClass + "( |$)");
var aElem = this.byTagName("*", oParent);
for (var i = 0; i < aElem.length; i++) reClass.test(aElem[i].className) && aClass.push(aElem[i]);
return aClass
},
byTagName: function(elem, obj) {
return (obj || document).getElementsByTagName(elem)
}
};
var dragMinWidth = 250;
var dragMinHeight = 124;
/*-------------------------- +
  拖拽函数
 +-------------------------- */
function drag(oDrag, handle)
{//武鸣人网站https://www.wuming.ren 网站很好记住,wuming.ren(武鸣拼音.ren域名后缀)
var disX = dixY = 0;
var oMin = get.byClass("min", oDrag)[0];
var oMax = get.byClass("max", oDrag)[0];
var oRevert = get.byClass("revert", oDrag)[0];
var oClose = get.byClass("close", oDrag)[0];
handle = handle || oDrag;
handle.style.cursor = "move";
handle.onmousedown = function (event)
{
var event = event || window.event;
disX = event.clientX - oDrag.offsetLeft;
disY = event.clientY - oDrag.offsetTop;
document.onmousemove = function (event)
{
var event = event || window.event;
var iL = event.clientX - disX;
var iT = event.clientY - disY;
var maxL = document.documentElement.clientWidth - oDrag.offsetWidth;
var maxT = document.documentElement.clientHeight - oDrag.offsetHeight;
iL <= 0 && (iL = 0);
iT <= 0 && (iT = 0);
iL >= maxL && (iL = maxL);
iT >= maxT && (iT = maxT);
oDrag.style.left = iL + "px";
oDrag.style.top = iT + "px";
return false
};
document.onmouseup = function ()
{
document.onmousemove = null;
document.onmouseup = null;
this.releaseCapture && this.releaseCapture()
};
this.setCapture && this.setCapture();
return false
};
//最大化按钮
oMax.onclick = function ()
{
oDrag.style.top = oDrag.style.left = 0;
oDrag.style.width = document.documentElement.clientWidth - 2 + "px";
oDrag.style.height = document.documentElement.clientHeight - 2 + "px";
this.style.display = "none";
oRevert.style.display = "block";
};
//还原按钮
oRevert.onclick = function ()
{
oDrag.style.width = dragMinWidth + "px";
oDrag.style.height = dragMinHeight + "px";
oDrag.style.left = (document.documentElement.clientWidth - oDrag.offsetWidth) / 2 + "px";
oDrag.style.top = (document.documentElement.clientHeight - oDrag.offsetHeight) / 2 + "px";
this.style.display = "none";
oMax.style.display = "block";
};
//最小化按钮
oMin.onclick = oClose.onclick = function ()
{
oDrag.style.display = "none";
var oA = document.createElement("a");
oA.className = "open";
oA.href = "javascript:;";
oA.title = "还原";
document.body.appendChild(oA);
oA.onclick = function ()
{
oDrag.style.display = "block";
document.body.removeChild(this);
this.onclick = null;
};
};
//阻止冒泡
oMin.onmousedown = oMax.onmousedown = oClose.onmousedown = function (event)
{
this.onfocus = function () {this.blur()};
(event || window.event).cancelBubble = true
};
}//武鸣人网站https://www.wuming.ren 网站很好记住,wuming.ren(武鸣拼音.ren域名后缀)
/*-------------------------- +
  改变大小函数
 +-------------------------- */
function resize(oParent, handle, isLeft, isTop, lockX, lockY)
{
handle.onmousedown = function (event)
{
var event = event || window.event;
var disX = event.clientX - handle.offsetLeft;
var disY = event.clientY - handle.offsetTop;
var iParentTop = oParent.offsetTop;
var iParentLeft = oParent.offsetLeft;
var iParentWidth = oParent.offsetWidth;
var iParentHeight = oParent.offsetHeight;
document.onmousemove = function (event)
{
var event = event || window.event;
var iL = event.clientX - disX;
var iT = event.clientY - disY;
var maxW = document.documentElement.clientWidth - oParent.offsetLeft - 2;
var maxH = document.documentElement.clientHeight - oParent.offsetTop - 2;
var iW = isLeft ? iParentWidth - iL : handle.offsetWidth + iL;
var iH = isTop ? iParentHeight - iT : handle.offsetHeight + iT;
isLeft && (oParent.style.left = iParentLeft + iL + "px");
isTop && (oParent.style.top = iParentTop + iT + "px");
iW < dragMinWidth && (iW = dragMinWidth);
iW > maxW && (iW = maxW);
lockX || (oParent.style.width = iW + "px");
iH < dragMinHeight && (iH = dragMinHeight);
iH > maxH && (iH = maxH);
lockY || (oParent.style.height = iH + "px");
if((isLeft && iW == dragMinWidth) || (isTop && iH == dragMinHeight)) document.onmousemove = null;
return false;
};
document.onmouseup = function ()
{
document.onmousemove = null;
document.onmouseup = null;
};
return false;
}
};
window.onload = window.onresize = function ()
{//武鸣人网站https://www.wuming.ren 网站很好记住,wuming.ren(武鸣拼音.ren域名后缀)
var oDrag = document.getElementById("www_wuming_ren");
var oTitle = get.byClass("title", oDrag)[0];
var oL = get.byClass("_wuming__ren_2", oDrag)[0];
var oT = get.byClass("wuming__3", oDrag)[0];
var oR = get.byClass("wuming_4", oDrag)[0];
var oB = get.byClass("wuming_ren_5", oDrag)[0];
var oLT = get.byClass("www_wuming__ren_6", oDrag)[0];
var oTR = get.byClass("www__wuming__ren_7", oDrag)[0];
var oBR = get.byClass("wuming_ren_8", oDrag)[0];
var oLB = get.byClass("wuming_ren_9", oDrag)[0];
drag(oDrag, oTitle);
//四角
resize(oDrag, oLT, true, true, false, false);
resize(oDrag, oTR, false, true, false, false);
resize(oDrag, oBR, false, false, false, false);
resize(oDrag, oLB, true, false, false, false);
//四边
resize(oDrag, oL, true, false, false, true);
resize(oDrag, oT, false, true, true, false);
resize(oDrag, oR, false, false, false, true);
resize(oDrag, oB, false, false, true, false);
oDrag.style.left = (document.documentElement.clientWidth - oDrag.offsetWidth) / 2 + "px";
oDrag.style.top = (document.documentElement.clientHeight - oDrag.offsetHeight) / 2 + "px";
}//武鸣人网站https://www.wuming.ren 网站很好记住,wuming.ren(武鸣拼音.ren域名后缀)
</script>
</head>
<body>
<a href="https://www.wuming.ren">武鸣人</a>,各种信息资源免费发布,分享励志语录经典短句,减肥健身常识,各种js特效代码。网站很好记住,wuming.ren(武鸣拼音.ren域名后缀)<hr>
<!--欢迎来到武鸣人信息资源平台,各种信息免费发布,资源共享合作共赢,分享互联网流行的励志语录经典短句,减肥健身健康小常识及打卡记录,收集各种js特效代码。-->
<!--<script type="text/javascript" src="https://www.wuming.ren/ad/tc.js"></script>-->
<script type="text/javascript" src="https://www.wuming.ren/ad/a.js"></script>
<div id="www_wuming_ren">
    <div class="title">
        <h2>这是一个可以拖动的窗口</h2>
        <div>
            <a class="min" href="javascript:;" title="最小化"></a>
            <a class="max" href="javascript:;" title="最大化"></a>
            <a class="revert" href="javascript:;" title="还原"></a>
            <a class="close" href="javascript:;" title="关闭"></a>
        </div>
    </div>
    <div class="_wuming__ren_2"></div>
    <div class="wuming__3"></div>
    <div class="wuming_4"></div>
    <div class="wuming_ren_5"></div>
    <div class="www_wuming__ren_6"></div>
    <div class="www__wuming__ren_7"></div>
    <div class="wuming_ren_8"></div>
    <div class="wuming_ren_9"></div>
    <div class="content">
        ① 窗口可以拖动;<br />
        ② 窗口可以通过八个方向改变大小;<br />
        ③ 窗口可以最小化、最大化、还原、关闭;<br />
        ④ 限制窗口最小宽度/高度。<br />
    </div>
</div>
</body>
</html>


0
0
收藏0
回帖

支持拖拽功能带最大化最小化窗口js特效 期待您的回复!

取消
载入表情清单……
载入颜色清单……
插入网络图片

取消确定

图片上传中
编辑器信息
提示信息