代码语言
.
CSharp
.
JS
Java
Asp.Net
C
MSSQL
PHP
Css
PLSQL
Python
Shell
EBS
ASP
Perl
ObjC
VB.Net
VBS
MYSQL
GO
Delphi
AS
DB2
Domino
Rails
ActionScript
Scala
代码分类
文件
系统
字符串
数据库
网络相关
图形/GUI
多媒体
算法
游戏
Jquery
Extjs
Android
HTML5
菜单
网页交互
WinForm
控件
企业应用
安全与加密
脚本/批处理
开放平台
其它
【
CSharp
】
javascript 模仿windows拖动 封装类
作者:
CSDN
/ 发布于
2012/1/11
/
799
<div>javascript 模仿windows拖动 封装类 <span style="color: rgb(0,128,0)">/*</span><span style="color: rgb(0,128,0)">* * CreateDate 2011-8-22 18:34:34 * * @type Javascript Document * * Description of moveElement.class * * @example drop.reg("span","div"); * </span><span style="color: rgb(0,128,0)">*/</span><span style="color: rgb(0,0,0)"> </span><span style="color: rgb(0,0,255)">var</span><span style="color: rgb(0,0,0)"> drop</span><span style="color: rgb(0,0,0)">=</span><span style="color: rgb(0,0,0)">{ reg: </span><span style="color: rgb(0,0,255)">function</span><span style="color: rgb(0,0,0)"> (handler, movediv, cursor) { </span><span style="color: rgb(0,128,0)">//</span><span style="color: rgb(0,128,0)"> 注册鼠标移动的一些事件。</span><span style="color: rgb(0,128,0)"> </span><span style="color: rgb(0,0,0)"> </span><span style="color: rgb(0,0,255)">var</span><span style="color: rgb(0,0,0)"> isclick </span><span style="color: rgb(0,0,0)">=</span><span style="color: rgb(0,0,0)"> </span><span style="color: rgb(0,0,255)">false</span><span style="color: rgb(0,0,0)">; </span><span style="color: rgb(0,0,255)">var</span><span style="color: rgb(0,0,0)"> clickleft </span><span style="color: rgb(0,0,0)">=</span><span style="color: rgb(0,0,0)"> </span><span style="color: rgb(0,0,0)">0</span><span style="color: rgb(0,0,0)">; </span><span style="color: rgb(0,0,255)">var</span><span style="color: rgb(0,0,0)"> clicktop </span><span style="color: rgb(0,0,0)">=</span><span style="color: rgb(0,0,0)"> </span><span style="color: rgb(0,0,0)">0</span><span style="color: rgb(0,0,0)">; </span><span style="color: rgb(0,0,255)">var</span><span style="color: rgb(0,0,0)"> target </span><span style="color: rgb(0,0,0)">=</span><span style="color: rgb(0,0,0)"> </span><span style="color: rgb(0,0,255)">this</span><span style="color: rgb(0,0,0)">.$(handler); </span><span style="color: rgb(0,0,255)">var</span><span style="color: rgb(0,0,0)"> movediv </span><span style="color: rgb(0,0,0)">=</span><span style="color: rgb(0,0,0)"> </span><span style="color: rgb(0,0,255)">this</span><span style="color: rgb(0,0,0)">.$(movediv); movediv.style.position</span><span style="color: rgb(0,0,0)">=</span><span style="color: rgb(0,0,0)">"</span><span style="color: rgb(0,0,0)">absolute</span><span style="color: rgb(0,0,0)">"</span><span style="color: rgb(0,0,0)">; target.style.cursor </span><span style="color: rgb(0,0,0)">=</span><span style="color: rgb(0,0,0)"> cursor </span><span style="color: rgb(0,0,0)">||</span><span style="color: rgb(0,0,0)"> </span><span style="color: rgb(0,0,0)">"</span><span style="color: rgb(0,0,0)">move</span><span style="color: rgb(0,0,0)">"</span><span style="color: rgb(0,0,0)">; </span><span style="color: rgb(0,0,255)">function</span><span style="color: rgb(0,0,0)"> clickdrop(e) { </span><span style="color: rgb(0,128,0)">//</span><span style="color: rgb(0,128,0)"> 按下鼠标左键时的事件。</span><span style="color: rgb(0,128,0)"> </span><span style="color: rgb(0,0,0)"> e </span><span style="color: rgb(0,0,0)">=</span><span style="color: rgb(0,0,0)"> window.event </span><span style="color: rgb(0,0,0)">||</span><span style="color: rgb(0,0,0)"> e; </span><span style="color: rgb(0,128,0)">//</span><span style="color: rgb(0,128,0)"> 获取当前事件对象。</span><span style="color: rgb(0,128,0)"> </span><span style="color: rgb(0,0,0)"> </span><span style="color: rgb(0,0,255)">var</span><span style="color: rgb(0,0,0)"> tag</span><span style="color: rgb(0,0,0)">=</span><span style="color: rgb(0,0,0)">document.createElement(</span><span style="color: rgb(0,0,0)">"</span><span style="color: rgb(0,0,0)">div</span><span style="color: rgb(0,0,0)">"</span><span style="color: rgb(0,0,0)">) tag.id</span><span style="color: rgb(0,0,0)">=</span><span style="color: rgb(0,0,0)">"</span><span style="color: rgb(0,0,0)">move</span><span style="color: rgb(0,0,0)">"</span><span style="color: rgb(0,0,0)">; tag.style.width</span><span style="color: rgb(0,0,0)">=</span><span style="color: rgb(0,0,0)">movediv.style.width; tag.style.height</span><span style="color: rgb(0,0,0)">=</span><span style="color: rgb(0,0,0)">movediv.style.height; tag.style.position</span><span style="color: rgb(0,0,0)">=</span><span style="color: rgb(0,0,0)">"</span><span style="color: rgb(0,0,0)">absolute</span><span style="color: rgb(0,0,0)">"</span><span style="color: rgb(0,0,0)">; tag.style.left</span><span style="color: rgb(0,0,0)">=</span><span style="color: rgb(0,0,0)">movediv.style.left; tag.style.top</span><span style="color: rgb(0,0,0)">=</span><span style="color: rgb(0,0,0)">movediv.style.top; document.getElementsByTagName(</span><span style="color: rgb(0,0,0)">"</span><span style="color: rgb(0,0,0)">body</span><span style="color: rgb(0,0,0)">"</span><span style="color: rgb(0,0,0)">)[</span><span style="color: rgb(0,0,0)">0</span><span style="color: rgb(0,0,0)">].appendChild(tag); isclick </span><span style="color: rgb(0,0,0)">=</span><span style="color: rgb(0,0,0)"> </span><span style="color: rgb(0,0,255)">true</span><span style="color: rgb(0,0,0)">; </span><span style="color: rgb(0,128,0)">//</span><span style="color: rgb(0,128,0)"> 记录已经准备开始移动了。</span><span style="color: rgb(0,128,0)"> </span><span style="color: rgb(0,0,0)"> clickleft </span><span style="color: rgb(0,0,0)">=</span><span style="color: rgb(0,0,0)"> e.clientX </span><span style="color: rgb(0,0,0)">-</span><span style="color: rgb(0,0,0)"> parseInt(movediv.style.left); </span><span style="color: rgb(0,128,0)">//</span><span style="color: rgb(0,128,0)"> 记录当前坐标轴。</span><span style="color: rgb(0,128,0)"> </span><span style="color: rgb(0,0,0)"> clicktop </span><span style="color: rgb(0,0,0)">=</span><span style="color: rgb(0,0,0)"> e.clientY </span><span style="color: rgb(0,0,0)">-</span><span style="color: rgb(0,0,0)"> parseInt(movediv.style.top); } </span><span style="color: rgb(0,0,255)">function</span><span style="color: rgb(0,0,0)"> startdrop(e) { </span><span style="color: rgb(0,128,0)">//</span><span style="color: rgb(0,128,0)"> 鼠标开始移动时的事件。</span><span style="color: rgb(0,128,0)"> </span><span style="color: rgb(0,0,0)"> e </span><span style="color: rgb(0,0,0)">=</span><span style="color: rgb(0,0,0)"> window.event </span><span style="color: rgb(0,0,0)">||</span><span style="color: rgb(0,0,0)"> e; </span><span style="color: rgb(0,128,0)">//</span><span style="color: rgb(0,128,0)"> 获取当前事件对象。</span><span style="color: rgb(0,128,0)"> </span><span style="color: rgb(0,0,0)"> </span><span style="color: rgb(0,0,255)">if</span><span style="color: rgb(0,0,0)"> (</span><span style="color: rgb(0,0,0)">!</span><span style="color: rgb(0,0,0)">isclick) </span><span style="color: rgb(0,0,255)">return</span><span style="color: rgb(0,0,0)"> </span><span style="color: rgb(0,0,255)">false</span><span style="color: rgb(0,0,0)">; </span><span style="color: rgb(0,128,0)">//</span><span style="color: rgb(0,128,0)"> 如果isclick不等于真了返回。</span><span style="color: rgb(0,128,0)"> </span><span style="color: rgb(0,0,0)"> movediv.style.left</span><span style="color: rgb(0,0,0)">=</span><span style="color: rgb(0,0,0)">movediv.style.left</span><span style="color: rgb(0,0,0)">?</span><span style="color: rgb(0,0,0)">movediv.style.left:</span><span style="color: rgb(0,0,0)">1</span><span style="color: rgb(0,0,0)">; movediv.style.top</span><span style="color: rgb(0,0,0)">=</span><span style="color: rgb(0,0,0)">movediv.style.top</span><span style="color: rgb(0,0,0)">?</span><span style="color: rgb(0,0,0)">movediv.style.top:</span><span style="color: rgb(0,0,0)">1</span><span style="color: rgb(0,0,0)">; document.getElementById(</span><span style="color: rgb(0,0,0)">"</span><span style="color: rgb(0,0,0)">move</span><span style="color: rgb(0,0,0)">"</span><span style="color: rgb(0,0,0)">).style.border</span><span style="color: rgb(0,0,0)">=</span><span style="color: rgb(0,0,0)">"</span><span style="color: rgb(0,0,0)">1px dotted #000000</span><span style="color: rgb(0,0,0)">"</span><span style="color: rgb(0,0,0)"> document.getElementById(</span><span style="color: rgb(0,0,0)">"</span><span style="color: rgb(0,0,0)">move</span><span style="color: rgb(0,0,0)">"</span><span style="color: rgb(0,0,0)">).style.left </span><span style="color: rgb(0,0,0)">=</span><span style="color: rgb(0,0,0)"> e.clientX </span><span style="color: rgb(0,0,0)">-</span><span style="color: rgb(0,0,0)"> clickleft </span><span style="color: rgb(0,0,0)">+</span><span style="color: rgb(0,0,0)"> </span><span style="color: rgb(0,0,0)">"</span><span style="color: rgb(0,0,0)">px</span><span style="color: rgb(0,0,0)">"</span><span style="color: rgb(0,0,0)"> document.getElementById(</span><span style="color: rgb(0,0,0)">"</span><span style="color: rgb(0,0,0)">move</span><span style="color: rgb(0,0,0)">"</span><span style="color: rgb(0,0,0)">).style.top</span><span style="color: rgb(0,0,0)">=</span><span style="color: rgb(0,0,0)"> e.clientY </span><span style="color: rgb(0,0,0)">-</span><span style="color: rgb(0,0,0)"> clicktop </span><span style="color: rgb(0,0,0)">+</span><span style="color: rgb(0,0,0)"> </span><span style="color: rgb(0,0,0)">"</span><span style="color: rgb(0,0,0)">px</span><span style="color: rgb(0,0,0)">"</span><span style="color: rgb(0,0,0)">; } </span><span style="color: rgb(0,0,255)">function</span><span style="color: rgb(0,0,0)"> endrop(e) { </span><span style="color: rgb(0,128,0)">//</span><span style="color: rgb(0,128,0)"> 释放鼠标左键时的事件。</span><span style="color: rgb(0,128,0)"> </span><span style="color: rgb(0,0,0)"> e </span><span style="color: rgb(0,0,0)">=</span><span style="color: rgb(0,0,0)"> window.event </span><span style="color: rgb(0,0,0)">||</span><span style="color: rgb(0,0,0)"> e; </span><span style="color: rgb(0,0,255)">if</span><span style="color: rgb(0,0,0)"> (isclick) { </span><span style="color: rgb(0,128,0)">//</span><span style="color: rgb(0,128,0)"> 如果isclick还为真那么就赋值为假。</span><span style="color: rgb(0,128,0)"> </span><span style="color: rgb(0,0,0)"> movediv.style.left </span><span style="color: rgb(0,0,0)">=</span><span style="color: rgb(0,0,0)"> e.clientX </span><span style="color: rgb(0,0,0)">-</span><span style="color: rgb(0,0,0)"> clickleft </span><span style="color: rgb(0,0,0)">+</span><span style="color: rgb(0,0,0)"> </span><span style="color: rgb(0,0,0)">"</span><span style="color: rgb(0,0,0)">px</span><span style="color: rgb(0,0,0)">"</span><span style="color: rgb(0,0,0)">; </span><span style="color: rgb(0,128,0)">//</span><span style="color: rgb(0,128,0)"> 把鼠标当前移动的位置赋值给div</span><span style="color: rgb(0,128,0)"> </span><span style="color: rgb(0,0,0)"> movediv.style.top </span><span style="color: rgb(0,0,0)">=</span><span style="color: rgb(0,0,0)"> e.clientY </span><span style="color: rgb(0,0,0)">-</span><span style="color: rgb(0,0,0)"> clicktop </span><span style="color: rgb(0,0,0)">+</span><span style="color: rgb(0,0,0)"> </span><span style="color: rgb(0,0,0)">"</span><span style="color: rgb(0,0,0)">px</span><span style="color: rgb(0,0,0)">"</span><span style="color: rgb(0,0,0)">; </span><span style="color: rgb(0,128,0)">//</span><span style="color: rgb(0,128,0)"> 当前位置减去开始位置就是层当前存放的位置。</span><span style="color: rgb(0,128,0)"> </span><span style="color: rgb(0,0,0)"> document.getElementsByTagName(</span><span style="color: rgb(0,0,0)">"</span><span style="color: rgb(0,0,0)">body</span><span style="color: rgb(0,0,0)">"</span><span style="color: rgb(0,0,0)">)[</span><span style="color: rgb(0,0,0)">0</span><span style="color: rgb(0,0,0)">].removeChild(document.getElementById(</span><span style="color: rgb(0,0,0)">"</span><span style="color: rgb(0,0,0)">move</span><span style="color: rgb(0,0,0)">"</span><span style="color: rgb(0,0,0)">)) </span><span style="color: rgb(0,0,255)">if</span><span style="color: rgb(0,0,0)"> (</span><span style="color: rgb(0,0,255)">this</span><span style="color: rgb(0,0,0)">.isIE) movediv.releaseCapture(); </span><span style="color: rgb(0,128,0)">//</span><span style="color: rgb(0,128,0)">该函数从当前的窗口释放鼠标捕获,并恢复通常的鼠标输入处理。</span><span style="color: rgb(0,128,0)"> </span><span style="color: rgb(0,0,0)"> isclick </span><span style="color: rgb(0,0,0)">=</span><span style="color: rgb(0,0,0)"> </span><span style="color: rgb(0,0,255)">false</span><span style="color: rgb(0,0,0)">; document.documentElement.onmousemove </span><span style="color: rgb(0,0,0)">=</span><span style="color: rgb(0,0,0)"> </span><span style="color: rgb(0,0,255)">null</span><span style="color: rgb(0,0,0)">; } } target.onmouseover</span><span style="color: rgb(0,0,0)">=</span><span style="color: rgb(0,0,0)"> clickdrop; target.onmousedown </span><span style="color: rgb(0,0,0)">=</span><span style="color: rgb(0,0,0)"> clickdrop; </span><span style="color: rgb(0,128,0)">//</span><span style="color: rgb(0,128,0)"> 鼠标按下事件。</span><span style="color: rgb(0,128,0)"> </span><span style="color: rgb(0,0,0)"> document.onmouseup </span><span style="color: rgb(0,0,0)">=</span><span style="color: rgb(0,0,0)"> endrop; </span><span style="color: rgb(0,128,0)">//</span><span style="color: rgb(0,128,0)"> 鼠标释放事件。</span><span style="color: rgb(0,128,0)"> </span><span style="color: rgb(0,0,0)"> document.onmousemove </span><span style="color: rgb(0,0,0)">=</span><span style="color: rgb(0,0,0)"> startdrop; </span><span style="color: rgb(0,128,0)">//</span><span style="color: rgb(0,128,0)"> 鼠标移动事件。</span><span style="color: rgb(0,128,0)"> </span><span style="color: rgb(0,0,0)"> </span><span style="color: rgb(0,128,0)">//</span><span style="color: rgb(0,128,0)"> movediv.onselectstart = movediv.oncontextmenu = function () { return false; }; // 禁止选择和右键菜单。</span><span style="color: rgb(0,128,0)"> </span><span style="color: rgb(0,0,0)"> }, isIE: (navigator.appName </span><span style="color: rgb(0,0,0)">==</span><span style="color: rgb(0,0,0)"> </span><span style="color: rgb(0,0,0)">"</span><span style="color: rgb(0,0,0)">Microsoft Internet Explorer</span><span style="color: rgb(0,0,0)">"</span><span style="color: rgb(0,0,0)">) </span><span style="color: rgb(0,0,0)">||</span><span style="color: rgb(0,0,0)"> window.ActiveXObject, </span><span style="color: rgb(0,128,0)">//</span><span style="color: rgb(0,128,0)"> 判断是否为IE。,</span><span style="color: rgb(0,128,0)"> </span><span style="color: rgb(0,0,0)"> $:</span><span style="color: rgb(0,0,255)">function</span><span style="color: rgb(0,0,0)"> (objectId)</span><span style="color: rgb(0,128,0)">//</span><span style="color: rgb(0,128,0)">获取id的函数</span><span style="color: rgb(0,128,0)"> </span><span style="color: rgb(0,0,0)"> { </span><span style="color: rgb(0,0,255)">var</span><span style="color: rgb(0,0,0)"> id</span><span style="color: rgb(0,0,0)">=</span><span style="color: rgb(0,0,255)">null</span><span style="color: rgb(0,0,0)">; </span><span style="color: rgb(0,0,255)">if</span><span style="color: rgb(0,0,0)">(document.getElementById </span><span style="color: rgb(0,0,0)">&&</span><span style="color: rgb(0,0,0)"> document.getElementById(objectId)) { </span><span style="color: rgb(0,128,0)">//</span><span style="color: rgb(0,128,0)"> W3C DOM</span><span style="color: rgb(0,128,0)"> </span><span style="color: rgb(0,0,0)"> id</span><span style="color: rgb(0,0,0)">=</span><span style="color: rgb(0,0,0)">document.getElementById(objectId); } </span><span style="color: rgb(0,0,255)">else</span><span style="color: rgb(0,0,0)"> </span><span style="color: rgb(0,0,255)">if</span><span style="color: rgb(0,0,0)"> (document.all </span><span style="color: rgb(0,0,0)">&&</span><span style="color: rgb(0,0,0)"> document.all(objectId)) { </span><span style="color: rgb(0,128,0)">//</span><span style="color: rgb(0,128,0)"> MSIE 4 DOM</span><span style="color: rgb(0,128,0)"> </span><span style="color: rgb(0,0,0)"> id</span><span style="color: rgb(0,0,0)">=</span><span style="color: rgb(0,0,0)">document.all(objectId); } </span><span style="color: rgb(0,0,255)">else</span><span style="color: rgb(0,0,0)"> </span><span style="color: rgb(0,0,255)">if</span><span style="color: rgb(0,0,0)"> (document.layers </span><span style="color: rgb(0,0,0)">&&</span><span style="color: rgb(0,0,0)"> document.layers[objectId]) { </span><span style="color: rgb(0,128,0)">//</span><span style="color: rgb(0,128,0)"> NN 4 DOM.. note: var won't find nested layers</span><span style="color: rgb(0,128,0)"> </span><span style="color: rgb(0,0,0)"> id</span><span style="color: rgb(0,0,0)">=</span><span style="color: rgb(0,0,0)">document.layers[objectId]; } </span><span style="color: rgb(0,0,255)">else</span><span style="color: rgb(0,0,0)"> { id</span><span style="color: rgb(0,0,0)">=</span><span style="color: rgb(0,0,0)">"</span><span style="color: rgb(0,0,0)">undefind</span><span style="color: rgb(0,0,0)">"</span><span style="color: rgb(0,0,0)">; } </span><span style="color: rgb(0,0,255)">return</span><span style="color: rgb(0,0,0)"> (id</span><span style="color: rgb(0,0,0)">==</span><span style="color: rgb(0,0,0)">"</span><span style="color: rgb(0,0,0)">undefined</span><span style="color: rgb(0,0,0)">"</span><span style="color: rgb(0,0,0)"> </span><span style="color: rgb(0,0,0)">||</span><span style="color: rgb(0,0,0)"> id</span><span style="color: rgb(0,0,0)">==</span><span style="color: rgb(0,0,255)">null</span><span style="color: rgb(0,0,0)">)</span><span style="color: rgb(0,0,0)">?</span><span style="color: rgb(0,0,0)">"</span><span style="color: rgb(0,0,0)">\u672a能获取节点</span><span style="color: rgb(0,0,0)">"</span><span style="color: rgb(0,0,0)">:id; } } </span></div>
试试其它关键字
模仿windows拖动
同语言下
.
文件IO 操作类库
.
Check图片类型[JPEG(.jpg 、.jpeg),TIF,GIF,BMP,PNG,P
.
机器名和IP取得(IPV4 IPV6)
.
Tiff转换Bitmap
.
linqHelper
.
MadieHelper.cs
.
RegHelper.cs
.
如果关闭一个窗体后激活另一个窗体的事件或方法
.
创建日志通用类
.
串口辅助开发类
可能有用的
.
C#实现的html内容截取
.
List 切割成几份 工具类
.
SQL查询 多列合并成一行用逗号隔开
.
一行一行读取txt的内容
.
C#动态修改文件夹名称(FSO实现,不移动文件)
.
c# 移动文件或文件夹
.
c#图片添加水印
.
Java PDF转换成图片并输出给前台展示
.
网站后台修改图片尺寸代码
.
处理大图片在缩略图时的展示
CSDN
贡献的其它代码
(
27
)
.
xml操作类
.
完全无组件,不用调用Excel.exe 导出数据到Excel
.
DropDownList手动构造一个下拉树形
.
判断是否低于IE6的版本
.
javascript 鼠标拖拉画图
.
取汉字首字母
.
字符串格式化通用类
.
mssql海量高效分页存储过程
.
.net 获取远程IP 得到省市
.
javascript 模仿windows拖动 封装类
Copyright © 2004 - 2024 dezai.cn. All Rights Reserved
站长博客
粤ICP备13059550号-3