- 浏览: 738269 次
文章分类
最新评论
-
dfjjfxyl:
开源项目推荐网站:http://binlily.imwork. ...
JAVA开源项目 -
喵喵大神:
这类免费API还是挺多的,博客上也整理过:https://my ...
Web Api --智能Api接口
js拖拽div移动
js拖拽div移动,就是鼠标点击住div,根据鼠标的位置来改变div的位置
如有转载,请标明来自此出处http://blog.csdn.net/qxs965266509,必须注意!
第一种方法如下:代码如下:
html代码如下:
<div id="message_box" style="position:absolute; background-color:#FFFFFF;border:solid 1px #000;width:420px;left:40%;top:20%;filter:alpha(opacity=100);opacity:1;visibility:hidden;z-index:1000;"> <table cellpadding="0" cellspacing="0" border="0" style="width:100%;border-collapse:collapse;"> <tr id="titleBar" style="height:22px; text-align:left; background-color:#547BC9;color:White; padding:3px;"> <th align="left" unselectable="on" ><span>详细信息</span><span onClick="closeProc();" style="float: right;cursor: hand;">×</span></th> </tr> <tr style="height:130px;padding:3px;" align="left" valign="top" unselectable="on"> <td> <table border='1px;' style="text-align: left;margin-top: 20px;font-size: 13px;"> <tr><td rowspan='3' class="js_head" style="width: 120px;"><img src="/static/images/face.jpg" style="width: 100px;height: 100px;margin-left: 10px;"/></td><td class="js_nickName"></td></tr> <tr><td class="js_phone"></td></tr> <tr><td>-$^_^$-</td></tr> <tr style="height: 1px;"><td colspan='2'><hr style='color: red;'/></td></tr> <tr><td colspan='2' class="js_mainBusiness"></td></tr> <tr style="height: 1px;"><td colspan='2'><hr style='color: red;'/></td></tr> <tr><td colspan='2' style="text-align: center"><input type="button" class="js_createRoomSendMessage" value="发消息" style="width: 70px;height: 35px;"></td></tr> </table> </td> <!----> </tr> </table> </div>
js代码如下:
function DragDivDrag(titleBarID, message_boxID, obj) { var Common = { getEvent: function () {//ie/ff if (document.all) { return window.event; } func = getEvent.caller; while (func != null) { var arg0 = func.arguments[0]; if (arg0) { if ((arg0.constructor == Event || arg0.constructor == MouseEvent) || (typeof (arg0) == "object" && arg0.preventDefault && arg0.stopPropagation)) { return arg0; } } func = func.caller; } return null; }, getMousePos: function (ev) { if (!ev) { ev = this.getEvent(); } if (ev.pageX || ev.pageY) { return { x: ev.pageX, y: ev.pageY }; } if (document.documentElement && document.documentElement.scrollTop) { return { x: ev.clientX + document.documentElement.scrollLeft - document.documentElement.clientLeft, y: ev.clientY + document.documentElement.scrollTop - document.documentElement.clientTop }; } else if (document.body) { return { x: ev.clientX + document.body.scrollLeft - document.body.clientLeft, y: ev.clientY + document.body.scrollTop - document.body.clientTop }; } }, getItself: function (id) { return "string" == typeof id ? document.getElementById(id) : id; }, getViewportSize: { w: (window.innerWidth) ? window.innerWidth : (document.documentElement && document.documentElement.clientWidth) ? document.documentElement.clientWidth : document.body.offsetWidth, h: (window.innerHeight) ? window.innerHeight : (document.documentElement && document.documentElement.clientHeight) ? document.documentElement.clientHeight : document.body.offsetHeight }, isIE: document.all ? true : false, setOuterHtml: function (obj, html) { var Objrange = document.createRange(); obj.innerHTML = html; Objrange.selectNodeContents(obj); var frag = Objrange.extractContents(); if (obj.parentNode != null) { obj.parentNode.insertBefore(frag, obj); obj.parentNode.removeChild(obj); } } } ///------------------------------------------------------------------------------------------------------ var Class = { create: function () { return function () { this.init.apply(this, arguments); } } } var Drag = Class.create(); Drag.prototype = { init: function (titleBar, message_box, Options) { //设置点击是否透明,默认不透明 titleBar = Common.getItself(titleBar); message_box = Common.getItself(message_box); this.dragArea = { maxLeft: 0, maxRight: Common.getViewportSize.w - message_box.offsetWidth - 2, maxTop: 0, maxBottom: Common.getViewportSize.h - message_box.offsetHeight - 2 }; if (Options) { this.opacity = Options.opacity ? (isNaN(parseInt(Options.opacity)) ? 100 : parseInt(Options.opacity)) : 100; this.keepOrigin = Options.keepOrigin ? ((Options.keepOrigin == true || Options.keepOrigin == false) ? Options.keepOrigin : false) : false; if (this.keepOrigin) { this.opacity = 50; } if (Options.area) { if (Options.area.left && !isNaN(parseInt(Options.area.left))) { this.dragArea.maxLeft = Options.area.left } ; if (Options.area.right && !isNaN(parseInt(Options.area.right))) { this.dragArea.maxRight = Options.area.right } ; if (Options.area.top && !isNaN(parseInt(Options.area.top))) { this.dragArea.maxTop = Options.area.top } ; if (Options.area.bottom && !isNaN(parseInt(Options.area.bottom))) { this.dragArea.maxBottom = Options.area.bottom } ; } } else { this.opacity = 100, this.keepOrigin = false; } this.originDragDiv = null; this.tmpX = 0; this.tmpY = 0; this.moveable = false; var dragObj = this; titleBar.onmousedown = function (e) { var ev = e || window.event || Common.getEvent(); //只允许通过鼠标左键进行拖拽,IE鼠标左键为1 FireFox为0 if (Common.isIE && ev.button == 1 || !Common.isIE && ev.button == 0) { } else { return false; } if (dragObj.keepOrigin) { dragObj.originDragDiv = document.createElement("div"); dragObj.originDragDiv.style.cssText = message_box.style.cssText; dragObj.originDragDiv.style.width = message_box.offsetWidth; dragObj.originDragDiv.style.height = message_box.offsetHeight; dragObj.originDragDiv.innerHTML = message_box.innerHTML; message_box.parentNode.appendChild(dragObj.originDragDiv); } dragObj.moveable = true; message_box.style.zIndex = dragObj.GetZindex() + 1; var downPos = Common.getMousePos(ev); dragObj.tmpX = downPos.x - message_box.offsetLeft; dragObj.tmpY = downPos.y - message_box.offsetTop; titleBar.style.cursor = "move"; if (Common.isIE) { message_box.setCapture(); } else { window.captureEvents(Event.MOUSEMOVE); } dragObj.SetOpacity(message_box, dragObj.opacity); //FireFox 去除容器内拖拽图片问题 if (ev.preventDefault) { ev.preventDefault(); ev.stopPropagation(); } document.onmousemove = function (e) { if (dragObj.moveable) { var ev = e || window.event || Common.getEvent(); //IE 去除容器内拖拽图片问题 if (document.all) //IE { ev.returnValue = false; } var movePos = Common.getMousePos(ev); message_box.style.left = Math.max(Math.min(movePos.x - dragObj.tmpX, dragObj.dragArea.maxRight), dragObj.dragArea.maxLeft) + "px"; message_box.style.top = Math.max(Math.min(movePos.y - dragObj.tmpY, dragObj.dragArea.maxBottom), dragObj.dragArea.maxTop) + "px"; } }; document.onmouseup = function () { if (dragObj.keepOrigin) { if (Common.isIE) { dragObj.originDragDiv.outerHTML = ""; } else { Common.setOuterHtml(dragObj.originDragDiv, ""); } } if (dragObj.moveable) { if (Common.isIE) { message_box.releaseCapture(); } else { window.releaseEvents(Event.MOUSEMOVE); } dragObj.SetOpacity(message_box, 100); titleBar.style.cursor = "default"; dragObj.moveable = false; dragObj.tmpX = 0; dragObj.tmpY = 0; } }; } }, SetOpacity: function (message_box, n) { if (Common.isIE) { message_box.filters.alpha.opacity = n; } else { message_box.style.opacity = n / 100; } }, GetZindex: function () { var maxZindex = 0; var divs = document.getElementsByTagName("div"); for (z = 0; z < divs.length; z++) { maxZindex = Math.max(maxZindex, divs[z].style.zIndex); } return maxZindex; } } new Drag(titleBarID, message_boxID, obj); //, area: { left: 50, right: 500, top: 100, bottom: 400} }
使用的时候,直接调用
DragDivDrag("titleBar", "message_box", { opacity: 100, keepOrigin: true });
代码中
new Drag(titleBarID, message_boxID, obj); //, area: { left: 50, right: 500, top: 100, bottom: 400}
area参数代表div可移动的范围
仅供参考,如有疑问,请留言...
如有转载,请标明来自此出处http://blog.csdn.net/qxs965266509,必须注意
第二中拖动的实现代码:<!-- Baidu Button BEGIN --> <script>window._bd_share_config = { "common": { "bdSnsKey": {}, "bdText": "", "bdMini": "1", "bdMiniList": false, "bdPic": "", "bdStyle": "0", "bdSize": "16" }, "share": {} }; with (document) 0[(getElementsByTagName('head')[0] || body).appendChild(createElement('script')).src = 'http://bdimg.share.baidu.com/static/api/js/share.js?v=89860593.js?cdnversion=' + ~(-new Date() / 36e5)];</script><!-- Baidu Button END --><!--192.168.100.33--><!-- Baidu Button BEGIN --><script type="text/javascript" id="bdshare_js" data="type=tools&uid=1536434"></script><script type="text/javascript" id="bdshell_js"></script><script type="text/javascript"> document.getElementById("bdshell_js").src = "http://bdimg.share.baidu.com/static/js/shell_v2.js?cdnversion=" + Math.ceil(new Date()/3600000) </script><!-- Baidu Button END --><!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> <title>自由拖动的DIV层方块</title> <meta http-equiv="content-type" content="text/html;charset=gb2312"> <style type="text/css"> #draggable{ background-color:green; font-size:9pt; padding:30px; color:white; width:360px; height:224px; position:absolute; } </style> <script type="text/javascript"> var rDrag = { o:null, init:function(o){ o.onmousedown = this.start; }, start:function(e){ var o; e = rDrag.fixEvent(e); e.preventDefault && e.preventDefault(); rDrag.o = o = this; o.x = e.clientX - rDrag.o.offsetLeft; o.y = e.clientY - rDrag.o.offsetTop; document.onmousemove = rDrag.move; document.onmouseup = rDrag.end; }, move:function(e){ e = rDrag.fixEvent(e); var oLeft,oTop; oLeft = e.clientX - rDrag.o.x; oTop = e.clientY - rDrag.o.y; rDrag.o.style.left = oLeft + 'px'; rDrag.o.style.top = oTop + 'px'; }, end:function(e){ e = rDrag.fixEvent(e); rDrag.o = document.onmousemove = document.onmouseup = null; }, fixEvent: function(e){ if (!e) { e = window.event; e.target = e.srcElement; e.layerX = e.offsetX; e.layerY = e.offsetY; } return e; } } window.onload = function(){ var obj = document.getElementById('draggable'); rDrag.init(obj); } </script> </head> <body> <div id="draggable">这个可以拖动!</a></div> </body> </html>
顶 1 踩 0 主题推荐 microsoft 鼠标 移动 firefox 图片 猜你在找 <script type="text/javascript"> var searchtitletags = 'js拖拽div移动' + ',' + 'microsoft,鼠标,移动,firefox,图片'; searchService({ index: 'blog', query: searchtitletags, from: 10, size: 10, appendTo: '#res-relatived', url: 'recommend', his: 2, client: "blog_cf_enhance", tmpl: '<dd style="background:url(http://static.blog.csdn.net/skin/default/images/blog-dot-red3.gif) no-repeat 0 10px;"><a href="#{ url }" title="#{ title }" strategy="#{ strategy }">#{ title }</a></dd>' }); </script><script type="text/javascript"> new Ad(4, 'ad_cen'); </script><script type="text/javascript"> var fileName = '14640591'; var commentscount = 1; var islock = false </script><script type="text/javascript" src="http://static.blog.csdn.net/scripts/comment.js"></script><script type="text/javascript"> new Ad(5, 'ad_bot'); </script><script type="text/javascript"> $(function () { $("#ad_frm_0").height("90px"); setTimeout(function(){ $("#ad_frm_2").height("200px"); },1000); if($("#comment_content").length>0) { $("#quick-reply").show(); $("#quick-reply").click(function(){ setEditorFocus(); }); } var d_top = $('#d-top-a'); document.onscroll = function () { var scrTop = (document.body.scrollTop || document.documentElement.scrollTop); if (scrTop > 500) { d_top.show(); } else { d_top.hide(); } } $('#d-top-a').click(function () { scrollTo(0, 0); this.blur(); return false; }); }); </script><style type="text/css"> .tag_list { background: none repeat scroll 0 0 #FFFFFF; border: 1px solid #D7CBC1; color: #000000; font-size: 12px; line-height: 20px; list-style: none outside none; margin: 10px 2% 0 1%; padding: 1px; } .tag_list h5 { background: none repeat scroll 0 0 #E0DBD3; color: #47381C; font-size: 12px; height: 24px; line-height: 24px; padding: 0 5px; margin: 0; } .tag_list h5 a { color: #47381C; } .classify { margin: 10px 0; padding: 4px 12px 8px; } .classify a { margin-right: 20px; white-space: nowrap; } </style><script type="text/javascript"> $(function(){ setTimeout(function(){ $(".comment_body:contains('回复')").each(function(index,item){ var u=$(this).text().split(':')[0].toString().replace("回复","") var thisComment=$(this); if(u) { $.getJSON("https://passport.csdn.net/get/nick?callback=?", {users: u}, function(a) { if(a!=null&&a.data!=null&&a.data.length>0) { nick=a.data[0].n; if(u!=nick) { thisComment.text(thisComment.text().replace(u,nick)); } } }); } }); },200); setTimeout(function(){ $("a img[src='http://js.tongji.linezing.com/stats.gif']").parent().css({"position":"absolute","left":"50%"}); },300); }); </script>核心技术类目
全部主题 Hadoop AWS 移动游戏 Java Android iOS Swift 智能硬件 Docker OpenStack VPN Spark ERP IE10 Eclipse CRM JavaScript 数据库 Ubuntu NFC WAP jQuery BI HTML5 Spring Apache .NET API HTML SDK IIS Fedora XML LBS Unity Splashtop UML components Windows Mobile Rails QEMU KDE Cassandra CloudStack FTC coremail OPhone CouchBase 云计算 iOS6 Rackspace Web App SpringSide Maemo Compuware 大数据 aptech Perl Tornado Ruby Hibernate ThinkPHP HBase Pure Solr Angular Cloud Foundry Redis Scala Django Bootstrap个人资料
- 访问:213119次
- 积分:4680
- 等级:
积分:4680- 排名:第1909名
- 原创:225篇
- 转载:1篇
- 译文:0篇
- 评论:154条
博客专栏
深入浅出之Struts2 文章:9篇
阅读:8386文章分类
文章存档
<!--归档统计-->- 2014年07月(1)
- 2014年03月(1)
- 2014年02月(1)
- 2013年12月(1)
- 2013年11月(5)
- 2013年10月(3)
- 2013年09月(11)
- 2013年08月(9)
- 2013年07月(5)
- 2013年06月(14)
- 2013年05月(16)
- 2013年04月(15)
- 2013年03月(19)
- 2013年02月(1)
- 2012年12月(13)
- 2012年11月(28)
- 2012年10月(16)
- 2012年09月(20)
- 2012年07月(5)
- 2012年06月(4)
- 2012年05月(11)
- 2012年04月(10)
- 2012年03月(6)
- 2012年02月(6)
- 2011年12月(1)
- 2011年11月(2)
- 2011年10月(2)
阅读排行
- 各种快递查询--Api接口(12318)
- 我的命运,我规划 -------大学生职业生涯规划_短期规划(7127)
- HTTP协议---HTTP请求中的常用请求字段和HTTP的响应状态码及响应头(5073)
- HTML5 LocalStorage本地存储和sessionStorage使用(4138)
- 数据库的查询与视图(3961)
- Java乔晓松-一次请求在同一个事务实现(3541)
- 城市公交查询--Api接口(3458)
- 火车车次查询-余票查询--Api接口(3188)
- Java乔晓松-2013android最新面试题(2812)
- Java_乔晓松_Java网络编程UDP实现黑窗口聊天(2787)
评论排行
- 我的命运,我规划 -------大学生职业生涯规划_短期规划(58)
- Java乔晓松-android使用GridView布局的电子相册&服务器获取图片(14)
- 火车车次查询-余票查询--Api接口(8)
- js数组的用法以及数组根据下标(数值或字符)移除元素(7)
- 数据库基本命令的总结(6)
- 苹果序列号/IMEI号查询--Api接口(4)
- Java乔晓松-httpURLConnection、URL、httpClient、httpPost、httpGet之代码详解篇(4)
- 索引和数据完整性约束的总结(4)
- Java乔晓松-2013Java最新面试题(4)
- Java乔晓松-android中调用系统拍照功能并显示拍照的图片(3)
<script type="text/javascript"> new Ad(12, 'ad_commend'); </script>推荐文章
最新评论
- 自定义spring容器--spring容器读取bean配置文件的原理
bq1073100909: 为什么我的报错呢?我是看了传智播客的视频写出来的,是不是jar包的问题,你的spring是多少版本的...
- 各种快递查询--Api接口
chong_wu: http://www.haoservice.com/docs/18 这个快递查询接口还不错,免费的...
- js中的referrer使用,返回上一页
qxs965266509: @a734998102:MSIE是判断浏览器是不是IE浏览器的http://blog.csdn.ne...
- js中的referrer使用,返回上一页
a734998102: 不知道你能不能看到, 我是新手啊,。。现在用到了这方面知识。。你能解释一下MSIE是什么啊 url...
- Java乔晓松-httpURLConnection、URL、httpClient、httpPost、httpGet之代码详解篇
qxs965266509: @geili_178:客户端百度云链接(客户端):http://pan.baidu.com/s/1q...
- Java乔晓松-httpURLConnection、URL、httpClient、httpPost、httpGet之代码详解篇
qxs965266509: @geili_178:服务器百度云链接(服务器):http://pan.baidu.com/s/1g...
- Java乔晓松-httpURLConnection、URL、httpClient、httpPost、httpGet之代码详解篇
geili_178: 你好,这两天在研究httpClient,希望博主能发一份源码,万分感谢,邮箱:873965057@q...
- Java乔晓松-android使用GridView布局的电子相册&服务器获取图片
xiao_wenrun: 楼主 能不能把服务端的源码发我一份啊!邮箱:461683480@qq.com
- Ajax长连接
qxs965266509: @lowitty:亲,是否阻塞还的看服务器的,我的服务器是Nodejs做的,并且,长连接的响应res...
- java线程中yield(),sleep(),wait()区别详解
u013323077: 真不要脸,复制粘贴别人的东西还贴上自己的名字!
相关推荐
DIV 拖动 JS移动DIV DIV位置移动DIV 拖动 JS移动DIV DIV位置移动DIV 拖动 JS移动DIV DIV位置移动DIV 拖动 JS移动DIV DIV位置移动
本下载包包括了3个js拖动特效,拖动DIV移动指定位置,一个实例是任意位置的拖动,不受限制,想拖动到哪里就拖动到哪里;另一个是指定位置的拖动,由左侧拖动到右侧指定位置,拖动结束后,左侧会少一个DIV,右侧新增...
JS实现鼠标拖动div移动(附效果演示)
纯Javascript编写的div拖拽以及用鼠标绘制div之间连接线,外部资源仅需要jquery。有以下功能: 1、创建节点 2、节点随鼠标任意拖动 3、切换拖动和画线模式 4、用鼠标绘制两个节点之间带有箭头的连线 5、连接线随节点...
1、html 拖动div进行相应顺序的排序,亲测可用,简单方便 2、适用于各大场景,通过相应的js拖动来执行相应的方法 3、可以下载应用,不懂的可以一起探讨
用js和jquery做的一个批量选择div,并能随意移动div,一个或多个div其选择。操作流程是先添加div然后选取所要移动的div,当div变成绿色的时候进行拖动。 是一个简单的js代码。
一个很好用的javaScript写的小程序,可实现div的拖动、变形。解压后直接拷到程序中就可运行
<br>移动位置,选中DIV后,如果单选组选中移动(-)(默认,快捷键为“-”)按住左键拖动位置后释放可批量移动位置,产生一段过度动画,不撤销选择的DIV可多次移动,如已移动完毕按Ctrl+Z撤销选择即可。...
可以实现行拖动,div拖动,图片拖动,例子中是行之间的拖动。
可以实现div在页面中随意拖动
利用JS实现可拖动的DIV效果,在原有基础上增加的限制在一定区域内的效果。方便,易用。可以很方便地移动到您的工程里面
NULL 博文链接:https://wangking717.iteye.com/blog/1718422
要拖动的div为最外层的div,这段代码对显示对话框的头部绑定鼠标监听事件,当鼠标移动时,整个div也相应的移动,具体的实现如下,感兴趣的朋友可以参考下
<br>移动位置,选中DIV后,如果单选组选中移动(-)(默认,快捷键为“-”)按住左键拖动位置后释放可批量移动位置,产生一段过度动画,不撤销选择的DIV可多次移动,如已移动完毕按Ctrl+Z撤销选择即可。...
JS自由拖拽DIV布局最新优化版2013-01-15 支持改变布局 添加删除DIV 在原作者ikaiser上优化,感谢ikaiser大神!
用JS和DIV 实现的简洁大方的弹窗,再也不用每次都下插件啦。使用时记得下载一个jquery.js库文件哦^-^
Javascript实现的交互式Div,Div随用户拖动而移动位置。
js模拟浏览器 Ctrl+F 查找 + div层鼠标拖动 改变位置 两个功能demo js模拟浏览器 Ctrl+F 查找 + div层鼠标拖动 改变位置 两个功能demo js模拟浏览器 Ctrl+F 查找 + div层鼠标拖动 改变位置 两个功能demo js模拟...
采用纯js方式实现网页DIV元素的动态拖动及位置移动操作程序
主要介绍了JavaScript实现可拖拽的拖动层Div的方法,拖拽页面中的div块可实现div块按照拖动轨迹移动的效果,涉及javascript鼠标事件、页面元素样式结合事件函数动态操作的相关技巧,需要的朋友可以参考下