<html>
<head>
<title>改变层的大小-阿里西西WEB开发</title>
<meta content="text/html; charset=gb2312" http-equiv="Content-Type">
<style>
{
box-sizing
:
border-box
;
moz-box-sizing
:
border-box
}
#testDiv {
background-color: buttonface;
background-repeat: repeat;
background-attachment: scroll;
color: #3969A5;
height: 300px;
left: 30px;
overflow: hidden;
width: 500;
z-index: 2;
border: 2px outset white;
margin: 0px;
padding: 2px;
background-position: 0% 50%
}
body {
font-family: Verdana;
font-size: 9pt
}
#innerNice {
background-color: white;
background-repeat: repeat;
background-attachment: scroll;
color: #3969A5;
height: 49%;
overflow: auto;
width: 100%;
border: 2px inset white;
padding: 8px;
background-position: 0% 50%
}
#innerNice2 {
background-color: white;
background-repeat: repeat;
background-attachment: scroll;
color: #3969A5;
height: 2%;
overflow: auto;
width: 100%;
border: 1px inset white;
padding: 1px;
background-position: 0% 50%
}
#innerNice1 {
background-color: white;
background-repeat: repeat;
background-attachment: scroll;
color: #3969A5;
height: 49%;
overflow: auto;
width: 100%;
border: 2px inset white;
padding: 8px;
background-position: 0% 50%
}
</style>
<SCRIPT language=javascript>
window.onload=init;
function init(){
divObj1 = document.getElementById("innerNice");
divObj2 = document.getElementById("innerNice1");
}
/////////////////////////////////////////////////////////////////////////
// Generic Resize by Erik Arvidsson //
// //
// You may use this script as long as this disclaimer is remained. //
// See www.dtek.chalmers.se/~d96erik/dhtml/ for mor info //
// //
// How to use this script! //
// Link the script in the HEAD and create a container (DIV, preferable //
// absolute positioned) and add the class="resizeMe" to it. //
/////////////////////////////////////////////////////////////////////////
var divObj1 = null; //This gets a value as soon as a resize start
var divObj2 = null;
var theobject1 = null; //This gets a value as soon as a resize start
var theobject2 = null;
function resizeObject1() {
this.el = null; //pointer to the object
this.dir = ""; //type of current resize (n, s, e, w, ne, nw, se, sw)
this.grabx = null; //Some useful values
this.graby = null;
this.width = null;
this.height = null;
this.left = null;
this.top = null;
}
function resizeObject2() {
this.el = null; //pointer to the object
this.dir = ""; //type of current resize (n, s, e, w, ne, nw, se, sw)
this.grabx = null; //Some useful values
this.graby = null;
this.width = null;
this.height = null;
this.left = null;
this.top = null;
}
//Find out what kind of resize! Return a string inlcluding the directions
function getDirection1(el) {
var xPos, yPos, offset, dir;
dir = "";
yPos = window.event.offsetY;
offset = 8; //The distance from the edge in pixels
if (yPos<offset) dir += "s";
else if (yPos > divObj1.offsetHeight+offset) dir += "n";
document.getElementById("aa").innerHTML = "yPos:"+yPos;
return dir;
}
function getDirection2(el) {
var xPos, yPos, offset, dir;
dir = "";
yPos = window.event.offsetY;
offset = 8; //The distance from the edge in pixels
if (yPos<offset) dir += "s";
else if (yPos > divObj2.offsetHeight-offset) dir += "n";
document.getElementById("bb").innerHTML = "yPos:"+yPos;
return dir;
}
function doDown() {
//alert("鼠标按下");
var el = getReal(event.srcElement);
if (el == null) {
theobject1 = null;
theobject2 = null;
return;
}
dir1 = getDirection1(el);
if (dir1 == "") return;
dir2 = getDirection2(el);
if (dir2 == "") return;
theobject1 = new resizeObject1();
theobject2 = new resizeObject2();
theobject1.el = divObj1;
theobject1.dir = dir1;
theobject1.grabx = window.event.clientX;
theobject1.graby = window.event.clientY;
theobject1.width = divObj1.offsetWidth;
theobject1.height = divObj1.offsetHeight;
theobject1.left = divObj1.offsetLeft;
theobject1.top = divObj1.offsetTop;
document.getElementById("cc").innerHTML = "theobject1.grabx:"+theobject1.grabx+";theobject1.graby:"+theobject1.graby+";theobject1.width:"+theobject1.width+";theobject1.height:"+theobject1.height+";theobject1.left:"+theobject1.left+";theobject1.top:"+theobject1.top;
theobject2.el = divObj2;
theobject2.dir = dir2;
theobject2.grabx = window.event.clientX;
theobject2.graby = window.event.clientY + 6 + divObj1.offsetHeight;
theobject2.width = divObj2.offsetWidth;
theobject2.height = divObj2.offsetHeight;
theobject2.left = divObj2.offsetLeft;
theobject2.top = divObj2.offsetTop;
document.getElementById("dd").innerHTML = "theobject2.grabx:"+theobject2.grabx+";theobject2.graby:"+theobject2.graby+";theobject2.width:"+theobject2.width+";theobject2.height:"+theobject2.height+";theobject2.left:"+theobject2.left+";theobject2.top:"+theobject2.top;
window.event.returnValue = false;
window.event.cancelBubble = true;
}
function doUp() {
if (theobject1 != null) {
theobject1 = null;
}
if (theobject2 != null) {
theobject2 = null;
}
}
function doMove() {
var el, xPos, yPos, str, xMin, yMin;
xMin = 8; //The smallest width possible
yMin = 8; // height
el = getReal(event.srcElement);
if (el.className == "resizeMe") {
str = getDirection1(el);
if (str == "") str = "default";
else str += "-resize";
el.style.cursor = str;
}
if(theobject1 != null) {
if (dir1.indexOf("s") != -1)
divObj1.style.height = Math.max(yMin, theobject1.height + window.event.clientY - theobject1.graby) + "px";
if (dir1.indexOf("n") != -1) {
divObj1.style.top=Math.min(theobject1.top+window.event.clientY-theobject1.graby,theobject1.top+theobject1.height-yMin)+"px";
divObj1.style.height = Math.max(yMin, theobject1.height - window.event.clientY + theobject1.graby) + "px";
}
}
if(theobject2 != null) {
if (dir2.indexOf("s") != -1)
divObj2.style.height = Math.max(yMin, theobject2.height - window.event.clientY + theobject1.graby) + "px";
if (dir2.indexOf("n") != -1) {
divObj2.style.height = Math.max(yMin, theobject2.height + window.event.clientY - theobject1.graby) + "px";
}
}
window.event.returnValue = false;
window.event.cancelBubble = true;
}
function getReal(el) {
temp = el;
while ((temp != null) && (temp.tagName != "BODY")) {
if(temp.id == "innerNice2") {
el = temp;
return el;
}
temp = temp.parentElement;
}
return el;
}
document.onmousedown = doDown;
document.onmouseup = doUp;
document.onmousemove = doMove;
</SCRIPT>
<meta content="Microsoft FrontPage 4.0" name="GENERATOR">
<meta name="ProgId" content="FrontPage.Editor.Document">
</head>
<body>
<div id="testDiv">
<div id="innerNice">
<p align="center">
</p>
<p align="center">
请在边框处拖动鼠标
<p>
</p>
<p>
</p>
<p>
</p>
</div>
<div id="innerNice2" class="resizeMe"></div>
<div id="innerNice1">
<p align="center">
</p>
<p align="center">
请在边框处拖动鼠标1
<p>
</p>
<p>
</p>
<p>
</p>
</div>
</div>
<div id="aa"></div>
<div id="bb"></div>
<div id="cc"></div>
<div id="dd"></div>
</body>
</html>
分享到:
相关推荐
直接拖拽div块,鼠标左键按下不松手,移动位置拖拽,松下放下
可拖动div边框改变大小的方法,jquery拖拽改变div大小效果,。。。。。。。。。。。。。。。。。。。。。。。。。
选中复选框(可移动、可调整大小)后,打开的DIV具有移动/调整大小的功能(此时移动/调整大小快捷键可使用); 反之,不可移动/调整大小(此时移动/调整大小快捷键无效) 单选框默认居中打开选中,无论有无保存DIV位置和...
基于Ext的javascript的DIV上下拖动,
Div拖动/调整大小实例 教你迅速的掌握如何写js 可以用鼠标控制div大小和位置 Div拖动/调整大小实例 教你迅速的掌握如何写js 可以用鼠标控制div大小和位置
拖拽并同时拖拽改变div大小暂无兼容性问题
js拖动div并拖动DIV的大小,js拖动div并拖动DIV的大小
div+css 布局 demo div+css 布局 demo div+css 布局 demo
dragresize 可让用户调整页面DIV的大小和位置 dragresize 可让用户调整页面DIV的大小和位置
div 拖动 div 拖动 div 拖动 div 拖动 div 拖动 div 拖动
JQ JS javascript layui UI组件 元素 div 拖动插件JQ JS javascript layui UI组件 元素 div 拖动插件
超酷 DIV拖拽 分页 超酷 DIV拖拽 分页 超酷 DIV拖拽 分页 超酷 DIV拖拽 分页 超酷 DIV拖拽 分页 超酷 DIV拖拽 分页 超酷 DIV拖拽 分页 超酷 DIV拖拽 分页 超酷 DIV拖拽 分页 超酷 DIV拖拽 分页 超酷 DIV拖拽 分页 ...
div 悬浮层 类似广告 右下方渐渐弹出
div弹出层demo 简单div弹出层例子
js拖动 拖拽div大小,内部随意文件操作。完美实现版
NULL 博文链接:https://wangking717.iteye.com/blog/1718422
基于jQuery可拖动的div,Demo,详细页面,有注释。
Jquery Sortable实现div拖动排序效果 Jquery Sortable实现div拖动排序效果
纯Javascript编写的div拖拽以及用鼠标绘制div之间连接线,外部资源仅需要jquery。有以下功能: 1、创建节点 2、节点随鼠标任意拖动 3、切换拖动和画线模式 4、用鼠标绘制两个节点之间带有箭头的连线 5、连接线随节点...