`
xxtianxiaxing
  • 浏览: 691046 次
  • 性别: Icon_minigender_1
  • 来自: 陕西
社区版块
存档分类
最新评论

关联div 拖动大小demo

    博客分类:
  • web
Web 
阅读更多
<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>



分享到:
评论

相关推荐

    纯js写的一个拖拽demo

    综上所述,这个"纯js写的一个拖拽demo"项目涵盖了JavaScript的基础知识,如事件处理、DOM操作、数据处理以及CSS的动态应用。通过实现这样一个DEMO,开发者可以深入理解拖放功能的工作原理,以及如何在JavaScript中...

    jquery-ui-dialog-demo

    Dialog 提供了丰富的选项,如自动调整大小、拖动、最小化、最大化、关闭按钮以及自定义标题等功能,使得在网页中创建弹出窗口变得非常灵活。 **Alert和Confirm对话框** 在 `jquery-ui-dialog-demo` 中,`alert` 和...

    GoogleMapAPIV3离线demo

    学习这个离线demo,你可以了解到如何在没有网络连接的情况下,模拟Google Maps的功能,这对在某些特殊环境下(如飞机、偏远地区)的应用开发很有价值。同时,掌握这些知识也将使你有能力创建出功能丰富的地图应用。

    google地图demo

    3. **地图初始化**:在JavaScript中,你需要指定一个容器元素(如div)来展示地图,然后调用`new google.maps.Map()`函数初始化地图,设置中心点坐标、地图类型、缩放级别等参数。 4. **标记(Marker)**:如果...

    demo(百度地图)实例

    4. **添加信息窗口**:标记通常会关联一个信息窗口,显示详细信息。可以使用`BMap.InfoWindow`创建信息窗口,并通过`marker.openInfoWindow(infoWindow)`打开它。 5. **地图事件监听**:通过`addEventListener`方法...

    webGis: Leaflet的demo程序

    4. **事件监听**:Leaflet提供了丰富的事件监听机制,允许开发者在用户与地图交互时执行特定操作,如点击地图、拖动标记等。 5. **交互式地图**:Leaflet支持地图的平移、缩放、旋转等交互操作,还可以自定义控制...

    真实好用的javaweb上使用的googlemap的demo

    这些信息窗口可以通过`google.maps.InfoWindow`类创建,并关联到标记上。 7. **路径绘制**:如果你需要在地图上展示路线或路径,可以使用`google.maps.Polyline`类来创建线形对象。通过添加多个坐标点,你可以绘制...

    lealfet基础功能讲解demo

    Leaflet 的地图创建是通过 `L.map` 函数完成的,需要指定一个DOM元素(通常是div)作为地图容器。例如: ```javascript var map = L.map('mapid').setView([51.505, -0.09], 13); ``` 这行代码创建了一个地图,...

    jsPlumb_demo11.rar

    jsPlumb 是一个开源的 JavaScript 库,专为构建可拖动和连接的用户界面而设计。它主要用于创建数据可视化、流程图和工作流应用程序,使得开发者可以通过图形化的方式表示数据间的关联。在本教程中,我们将深入探讨 ...

    百度地图web使用实例

    标记可以关联信息窗口,展示详细信息。创建`BMap.InfoWindow`对象,然后通过`open`方法打开: ```javascript var infoWindow = new BMap.InfoWindow("这里是详细信息"); marker.addEventListener("click", ...

    google-map-api-demo

    谷歌地图API提供了丰富的事件系统,你可以监听地图、标记等对象上的事件,如鼠标点击、拖动等,然后根据这些事件执行相应的处理函数。 11. **性能优化** 当处理大量数据或复杂交互时,需要考虑性能优化。这可能...

    jsp中动态添加树

    &lt;div id="jstree_demo_div"&gt;&lt;/div&gt; ``` 3. **初始化jsTree**:使用JavaScript来初始化jsTree,并传递配置选项,如数据源、主题、操作等。数据源可以是JSON格式,可以从服务器动态获取。 ```javascript $(document)...

    图表插件 echarts

    - **交互性**:ECharts支持鼠标和触摸事件,用户可以通过点击、拖拽等方式与图表进行交互,例如缩放、平移、刷选等。 - **高性能**:ECharts使用了高效的图形渲染引擎,即使面对大量数据也能快速绘制和更新图表。 - ...

    前端项目-jsxgraph.zip

    2. **丰富的图形元素**:jsxgraph支持绘制直线、圆、椭圆、多边形、函数曲线、图表等基本图形,并提供拖动、旋转、缩放等交互功能。 3. **几何构造**:它可以用于创建动态几何构造,允许用户构建几何关系并实时观察...

    uploadifive.zip

    3. **绑定触发元素**:将Uploadifive与一个HTML元素关联,通常是按钮或一个div,用户点击或拖放文件到此元素上触发上传。 4. **编写后端接口**:在服务器端编写接收文件的接口,处理上传的文件并返回响应。 5. **...

    jQuery插件zTree实现删除树子节点的方法示例

    &lt;div id="treeDemo" class="ztree"&gt;&lt;/div&gt; ()"&gt;删除黄冈市子节点 // ...设置和zNodes的代码 // 初始化zTree var treeObj = $.fn.zTree.init($("#treeDemo"), setting, zNodes); function ...

    RelVisJs:JavaScript关系可视化器

    1. **交互性**:用户可以通过点击、拖动节点来探索和操作可视化图,了解节点间的关联。 2. **自定义节点和边**:开发者可以自定义节点的形状、颜色和大小,以及边的样式、宽度和箭头,以适应不同的数据类型和设计...

    Vue样本图-如何使用Vue框架创建图组件

    6. **演示和源代码**:提供的`Vue-Samples-Graph-How-to-Create-a-Graph-Component.pdf`文档可能包含更详细的步骤和解释,而`VueGraph_Demo.zip`和`VueGraph_Src.zip`则可能是已经完成的图组件示例和源代码。...

    Hammer.js+轮播原理实现简洁的滑屏功能

    Hammer.js是一个专门为移动设备开发的JavaScript库,用于识别触摸手势,例如轻扫、双击、滑动、拖动等。通过使用Hammer.js,开发者可以轻松地为网页增加对触摸事件的支持,从而提升移动设备上用户的交互体验。轮播...

Global site tag (gtag.js) - Google Analytics