鼠标拖动改变层的大小

<html>
<head>
<title>拖动改变层的大小</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: 100%; overflow: auto; width:
100%; border: 2px inset white; padding: 8px;
background-position: 0% 50% }
</style>
<SCRIPT language=javascript>
var theobject = null;
function resizeObject() {
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 getDirection(el) {
var xPos, yPos, offset, dir;
dir = "";
xPos = window.event.offsetX;
yPos = window.event.offsetY;
offset = 8; //The distance from the edge in pixels
if (yPos<offset) dir += "n";
else if (yPos > el.offsetHeight-offset) dir += "s";
if (xPos<offset) dir += "w";
else if (xPos > el.offsetWidth-offset) dir += "e";
return dir;
}

function doDown() {
var el = getReal(event.srcElement, "className", "resizeMe");

if (el == null) {
theobject = null;
return;
}
dir = getDirection(el);
if (dir == "") return;
theobject = new resizeObject();

theobject.el = el;
theobject.dir = dir;
theobject.grabx = window.event.clientX;
theobject.graby = window.event.clientY;
theobject.width = el.offsetWidth;
theobject.height = el.offsetHeight;
theobject.left = el.offsetLeft;
theobject.top = el.offsetTop;
window.event.returnValue = false;
window.event.cancelBubble = true;
}

function doUp() {
if (theobject != null) {
theobject = null;
}
}

function doMove() {
var el, xPos, yPos, str, xMin, yMin;
xMin = 8; //The smallest width possible
yMin = 8; // height
el = getReal(event.srcElement, "className", "resizeMe");
if (el.className == "resizeMe") {
str = getDirection(el);
//Fix the cursor

if (str == "") str = "default";
else str += "-resize";
el.style.cursor = str;
}
//Dragging starts here
if(theobject != null) {
if (dir.indexOf("e") != -1)
theobject.el.style.width = Math.max(xMin, theobject.width + window.event.clientX - theobject.grabx) + "px";

if (dir.indexOf("s") != -1)
theobject.el.style.height = Math.max(yMin, theobject.height + window.event.clientY - theobject.graby) + "px";

if (dir.indexOf("w") != -1) {
theobject.el.style.left = Math.min(theobject.left + window.event.clientX - theobject.grabx, theobject.left + theobject.width - xMin) + "px";
theobject.el.style.width = Math.max(xMin, theobject.width - window.event.clientX + theobject.grabx) + "px";
}
if (dir.indexOf("n") != -1) {
theobject.el.style.top = Math.min(theobject.top + window.event.clientY - theobject.graby, theobject.top + theobject.height - yMin) + "px";
theobject.el.style.height = Math.max(yMin, theobject.height - window.event.clientY + theobject.graby) + "px";
}

window.event.returnValue = false;
window.event.cancelBubble = true;
}
}

function getReal(el, type, value) {
temp = el;
while ((temp != null) && (temp.tagName != "BODY")) {
if (eval("temp." + type) == value) {
el = temp;
return el;
}
temp = temp.parentElement;
}
return el;
}

document.onmousedown = doDown;
document.onmouseup = doUp;
document.onmousemove = doMove;
</SCRIPT>
</head>
<body>
<div class="resizeMe" id="testDiv">
<div id="innerNice">
<p align="center"> </p>
<p align="center">
请在边框处拖动鼠标</p>
<p> </p>
<p> </p>
<p> </p>
</div>
</div>
<div>http://www.999jiujiu.com/</div>
</body>
</html>

时间: 2024-07-28 14:57:23

鼠标拖动改变层的大小的相关文章

jQuery实现鼠标拖动改变Div高度

最近项目中需要在DashBoard页面做一个事件通知栏,该通知栏固定位于页面底部,鼠标拖动该DIV实现自动改变高度扩展内容显示区域. 以下是一个设计原型,基于jQuery实现,只实现了拖动效果,没有做页面美化,可以根据需求做相应修改. 直接上代码 1 <!DOCTYPE HTML PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd&quo

鼠标拖动改变DIV等网页元素的大小的最佳实践

1.初次实现 1.1 html代码 <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>div change

jquery 鼠标拖动改变div大小

一个非常简单的例子: <!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=&qu

拖动鼠标改变div层的大小宽度

<html> <head> <title>拖动鼠标改变div层的大小宽度-石家庄色彩顾问-亿诚</title> <meta content="text/html; charset=gb2312" http-equiv="Content-Type"> <style> { box-sizing: border-box; moz-box-sizing: border-box } #testDiv {

设置textarea文本框不可以拖动改变大小

设置textarea文本框不可以拖动改变大小:在默认状态下,textarea文本框可以使用鼠标拖动调整大小,可能在某些情况下需要禁止此功能.代码如下: <!DOCTYPE html> <html> <head> <meta charset=" utf-8"> <meta name="author" content="http://www.softwhy.com/" /> <titl

无边框对话框拖动改变大小的实现总结

相同是项目遇到的问题,要求是无边框的对话框要实现鼠标的拖动改变大小.无边框对话框跟有边框的实现肯定不一样喽. 我上网搜到一种方法是: 须要处理下面这三个消息: WM_NCHITTEST  WM_SETCURSOR  WM_NCLBUTTONDOWN  消息处理函数: UINT CXXXDlg::OnNcHitTest(UINT nHitTest, CPoint point) { CRect rect; GetWindowRect(&rect); if(point.x <= rect.left

改变窗体的大小(理解鼠标的操作事件和过程)

1.Designer.cs代码 namespace 手动改变自制窗体的大小 { partial class Form1 { /// <summary> /// 必需的设计器变量. /// </summary> private System.ComponentModel.IContainer components = null; /// <summary> /// 清理所有正在使用的资源. /// </summary> /// <param name=&

js鼠标控制图片的特效,滚轮控制放大、缩小、鼠标拖动、聚焦。。。

项目需要做一个js控制图片的特效,滚轮控制放大.缩小.鼠标拖动等效果,网上找方法,各种报错.不兼容...最终自己研究出一套方案如下: 代码直接从项目中拷了,就不整理格式了 <script type="text/javascript"> //图片特效 by jifei_mei //图片大小,记录放大或缩小图片前的大小 var pic_size = { width:0, height:0 }; //绑定滚轮滚动事件 if (window.addEventListener) {

【ActionScript】利用复制影片duplicateMovieClip与鼠标拖动跟随startDrag做出鼠标移动特效

上次在<[ActionScript]ActionScript2.0的Helloworld>(点击打开链接)中介绍了ActionScript2.0的基本用法. 这次准备打算用复制影片duplicateMovieClip与鼠标拖动跟随startDrag做出如下图的鼠标移动特效: 一.准备工作 1.首先还是与上次上一样,新建一个ActionScript2.0的文件,然后先保存一下.之后,如下图所示,通过插入->新建元件,或者Ctrl+F8,在类型中选项图形,命名随意,新建一个图形元件. 2.之