网站地图
首页
php教程
asp.net教程
手机开发
css教程
网页制作
办公数码
jsp教程
asp教程
ps教程
当前位置:
编程学习网
>>
办公数码
>
excel
> >
[拖动排序]拖动层div 代码
[拖动排序]拖动层div 代码
发布时间:2017-06-02
【www.gdgbn.com--excel】
提示:您可以先修改部分代码再运行
拖放效果
<script> var isIE = (document.all) ? true : false; var $ = function (id) { return "string" == typeof id ? document.getElementById(id) : id; }; var Class = { create: function() { return function() { this.initialize.apply(this, arguments); } } } var Extend = function(destination, source) { for (var property in source) { destination[property] = source[property]; } } var Bind = function(object, fun) { return function() { return fun.apply(object, arguments); } } var BindAsEventListener = function(object, fun) { return function(event) { return fun.call(object, (event || window.event)); } } var CurrentStyle = function(element){ return element.currentStyle || document.defaultView.getComputedStyle(element, null); } function addEventHandler(oTarget, sEventType, fnHandler) { if (oTarget.addEventListener) { oTarget.addEventListener(sEventType, fnHandler, false); } else if (oTarget.attachEvent) { oTarget.attachEvent("on" + sEventType, fnHandler); } else { oTarget["on" + sEventType] = fnHandler; } }; function removeEventHandler(oTarget, sEventType, fnHandler) { if (oTarget.removeEventListener) { oTarget.removeEventListener(sEventType, fnHandler, false); } else if (oTarget.detachEvent) { oTarget.detachEvent("on" + sEventType, fnHandler); } else { oTarget["on" + sEventType] = null; } }; //拖放程序 var Drag = Class.create(); Drag.prototype = { //拖放对象 initialize: function(drag, options) { this.Drag = $(drag);//拖放对象 this._x = this._y = 0;//记录鼠标相对拖放对象的位置 this._marginLeft = this._marginTop = 0;//记录margin //事件对象(用于绑定移除事件) this._fM = BindAsEventListener(this, this.Move); this._fS = Bind(this, this.Stop); this.SetOptions(options); this.Limit = !!this.options.Limit; this.mxLeft = parseInt(this.options.mxLeft); this.mxRight = parseInt(this.options.mxRight); this.mxTop = parseInt(this.options.mxTop); this.mxBottom = parseInt(this.options.mxBottom); this.LockX = !!this.options.LockX; this.LockY = !!this.options.LockY; this.Lock = !!this.options.Lock; this.onStart = this.options.onStart; this.onMove = this.options.onMove; this.onStop = this.options.onStop; this._Handle = $(this.options.Handle) || this.Drag; this._mxContainer = $(this.options.mxContainer) || null; this.Drag.style.position = "absolute"; //透明 if(isIE && !!this.options.Transparent){ //填充拖放对象 with(this._Handle.appendChild(document.createElement("div")).style){ width = height = "100%"; backgroundColor = "#fff"; filter = "alpha(opacity:0)"; } } addEventHandler(this._Handle, "mousedown", BindAsEventListener(this, this.Start)); }, //设置默认属性 SetOptions: function(options) { this.options = {//默认值 Handle:"",//设置触发对象(不设置则使用拖放对象) Limit:false,//是否设置范围限制(为true时下面参数有用,可以是负数) mxLeft:0,//左边限制 mxRight:9999,//右边限制 mxTop:0,//上边限制 mxBottom:9999,//下边限制 mxContainer:"",//指定限制在容器内 LockX:false,//是否锁定水平方向拖放 LockY:false,//是否锁定垂直方向拖放 Lock:false,//是否锁定 Transparent:false,//是否透明 onStart:function(){},//开始移动时执行 onMove:function(){},//移动时执行 onStop:function(){}//结束移动时执行 }; Extend(this.options, options || {}); }, //准备拖动 Start: function(oEvent) { if(this.Lock){ return; } if(this.Limit){ //修正错误范围参数 this.mxRight = Math.max(this.mxRight, this.mxLeft + this.Drag.offsetWidth); this.mxBottom = Math.max(this.mxBottom, this.mxTop + this.Drag.offsetHeight); //如果有容器必须设置position为relative来相对定位,并在获取offset之前设置 !this._mxContainer || CurrentStyle(this._mxContainer).position == "relative" || (this._mxContainer.style.position = "relative"); } //记录鼠标相对拖放对象的位置 this._x = oEvent.clientX - this.Drag.offsetLeft; this._y = oEvent.clientY - this.Drag.offsetTop; //记录margin this._marginLeft = parseInt(CurrentStyle(this.Drag).marginLeft) || 0; this._marginTop = parseInt(CurrentStyle(this.Drag).marginTop) || 0; //mousemove时移动 mouseup时停止 addEventHandler(document, "mousemove", this._fM); addEventHandler(document, "mouseup", this._fS); if(isIE){ //焦点丢失 addEventHandler(this._Handle, "losecapture", this._fS); //设置鼠标捕获 this._Handle.setCapture(); }else{ //焦点丢失 addEventHandler(window, "blur", this._fS); //阻止默认动作 oEvent.preventDefault(); }; //附加程序 this.onStart(); }, //拖动 Move: function(oEvent) { //判断是否锁定 if(this.Lock){ this.Stop(); return; }; //清除选择 window.getSelection ? window.getSelection().removeAllRanges() : document.selection.empty(); //设置移动参数 var iLeft = oEvent.clientX - this._x, iTop = oEvent.clientY - this._y; //设置范围限制 if(this.Limit){ //设置范围参数 var mxLeft = this.mxLeft, mxRight = this.mxRight, mxTop = this.mxTop, mxBottom = this.mxBottom; //如果设置了容器,再修正范围参数 if(!!this._mxContainer){ mxLeft = Math.max(mxLeft, 0); mxTop = Math.max(mxTop, 0); mxRight = Math.min(mxRight, this._mxContainer.clientWidth); mxBottom = Math.min(mxBottom, this._mxContainer.clientHeight); }; //修正移动参数 iLeft = Math.max(Math.min(iLeft, mxRight - this.Drag.offsetWidth), mxLeft); iTop = Math.max(Math.min(iTop, mxBottom - this.Drag.offsetHeight), mxTop); } //设置位置,并修正margin if(!this.LockX){ this.Drag.style.left = iLeft - this._marginLeft + "px"; } if(!this.LockY){ this.Drag.style.top = iTop - this._marginTop + "px"; } //附加程序 this.onMove(); }, //停止拖动 Stop: function() { //移除事件 removeEventHandler(document, "mousemove", this._fM); removeEventHandler(document, "mouseup", this._fS); if(isIE){ removeEventHandler(this._Handle, "losecapture", this._fS); this._Handle.releaseCapture(); }else{ removeEventHandler(window, "blur", this._fS); }; //附加程序 this.onStop(); } }; </script>
拖放状态:未开始 <script> var drag = new Drag("idDrag", { mxContainer: "idContainer", Handle: "idHandle", Limit: true, onStart: function(){ $("idShow").innerHTML = "开始拖放"; }, onMove: function(){ $("idShow").innerHTML = "left:"+this.Drag.offsetLeft+";top:"+this.Drag.offsetTop; }, onStop: function(){ $("idShow").innerHTML = "结束拖放"; } }); $("idReset").onclick = function(){ drag.Limit = true; drag.mxLeft = drag.mxTop = 0; drag.mxRight = drag.mxBottom = 9999; drag.LockX = drag.LockY = drag.Lock = false; } $("idLock").onclick = function(){ drag.Lock = true; } $("idLockX").onclick = function(){ drag.LockX = true; } $("idLockY").onclick = function(){ drag.LockY = true; } $("idLimit").onclick = function(){ drag.mxRight = drag.mxBottom = 200; } $("idLimitOff").onclick = function(){ drag.Limit = false; } </script>
提示:您可以先修改部分代码再运行
本文来源:
http://www.gdgbn.com/bangongshuma/17480/
上一篇:
json|js 控制execel表格
下一篇:
excel二级联动菜单_二级联动菜单
相关推荐
【phpstudy】PHP implode() 函数实例教程
【phpstudy】php print() 与printf()函数教程
phpstudy_PHP and AJAX 仿 Live与google 搜索框
phpstudy|PHP parse_str() 函数实例教程
asp.net core_ASP.NET 数据库连接方式
asp是什么意思_ASP技术ASPError对象属性
phpstudy_PHP ord() 函数作用及实例教程
[稳定免费虚拟主机]无广告免费虚拟主机空间
flash基础入门教程|flash入门教程:Flash Sound实例教程
闪图教程视频|闪图教程:非主流闪图制作教程
网友关注
[asp.net]asp 教程:Dictionary组件实例教程
【php教程pdf】php教程:PHP number_format ( )实例教程
【稳定免费虚拟主机】国外免费虚拟主机空间申请地址
[flash player]Flash 按钮实例教程
非主流效果教程怀旧非主流图片大全|非主流效果教程:怀旧非主流图片制作教程
[php教程pdf]php教程:PHP nl2br() 函数实例教程
php连接mysql实例|免费php+mysql全能型空间
flash动画制作教程_flash教程:flash Shape实例教程
android studio_AdRotator 实例教程
快速提高网站流量的办法|快速提高网站流量的办法
热门标签
拖动窗口有拖影
拖动文件的时候重启资源
拖动验证码
拖动完成上方拼图
拖动view
拖动鼠标
最新excel
excel
mysql导入excel表|mysql导入excel方法
excel
【excel长度超过255个字符】EXCEL长度超过255个字符导入SQL SERVER2005的方法
excel
asp.net core_ASP.NET Excel读写文件代码
excel
[phpstudy]php ExcelReader读取excel文件
excel
[asp.net core]asp.net 导出EXCEL文件二种方法
excel
【asp.net core】asp.net ajax下导出excel的解决办法
excel
【asp.net core】asp.net 导出excel与单元格中图片的方法:
excel
【php去除重复数据】php去除重复单词与取得所有链接 正则代码
excel
csrf-token|C#中dataset导出到excel
excel
.net导入excel时获取第一个sheet|.net导入excel时获取第一个Sheet名称
excel热门文章
exce
excel二级联动菜单_二级联动菜单
exce
excel批量转换为数字_ExcelFileParser导入excel数据
exce
[asp.net]asp 导航excel数据到mssql access mysql 等数据方法
exce
phpstudy|php 把excel批量导入到数据库代码
exce
如何查找手机位置_如何查找高质量的友情?
exce
excel下拉菜单怎么做|excel 宏制作基础教程
exce
【asp如何导出数据到excel文件】ASP如何导出数据到Excel表
exce
phpstudy|php 导入excel文档程序
exce
[phpstudy]php 导入数据到excel
exce
【substring截取字符串】JavaScript截取字符串
声明:本网站尊重并保护知识产权,根据《信息网络传播权保护条例》,如果我们转载的作品侵犯了您的权利,请在一个月内通知我们,我们会及时删除。
Copyright©2006-2019 编程学习网 www.gdgbn.com 版权所有