网站首页
关于深山
客户案例
业务范围
联系深山
网络投票系统
企业网站建设
旅行社网站建设
小程序
留言板
技术文章
许愿墙(qq爱墙)
技术首页
百度小程序开发
微信小程序开发
微信公众号开发
uni-app
asp函数库
ASP
asp.net
DIV+CSS
HTML
SEO搜索引擎忧化
下载类信息
个人空间
代码生成
电商
python
页面特效
表格特效
导航菜单
图形特效
表单特效
时间日期
色彩类别
链接特效
网页特效
系统硬件
网站公告
网页学习
技术类文章
网站类信息
订阅本栏目 RSS
您所在的位置:
深山工作室
>
页面特效
> 正文
拖动效果 封装 已经修改,适应火狐
蓝色理想 2009/5/2 21:35:40 深山行者 字体:
大
中
小
浏览 11112
以下为详细代码
<!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="Content-Type" content="text/html; charset=gb2312" /> <title>拖动效果 封装 已经修改,适应火狐</title> <style type="text/css"> <!-- body{margin:0px;padding:0px;font-size:12px;background:#eee;line-height:20px;} .bodyer{width:760px;margin:20px auto auto;border:1px dotted #ccc;background:#fff;} .t_rt{text-align:right;} h1,h2,h3,h4,h5,h6{font-weight:bold;margin:0px;padding:0px;font-size:12px;} ul,li{margin:0px;padding:0px;} li{list-style-type:none;} h1{margin:10px;padding-right:10px;padding-bottom:5px;border-bottom:1px dotted #ccc;} .preview{margin:10px;padding:10px;overflow:hidden;background:#eee;} .cont{padding:10px;} .cls{clear:both;} .hidden{display:none;} #sourse{border:1px dotted #ccc;width:600px;height:300px;margin:0px auto;} .textDiv{margin:10px 40px 10px;text-align:center;} h2{margin:0px 10px;background:#ccc;padding:5px;} .example{margin:10px;background:#FFF;border:1px dotted #ccc;padding:10px;} .authorInfo{width:760px; margin:10px auto 10px;text-align:center;} .c_666{color:#666;} .red{color:red;} .scrolldoorFrame{width:600px;border:1px solid #FFF;margin:0px auto;overflow:hidden;position:relative;height:400px;} .scrollUl{width:400px;border-bottom:1px solid #CCC;overflow:hidden;height:35px;} .scrollUl li{float:left;} .bor03{border:1px solid #ccc;border-top-width:0px;} .sd01{cursor:pointer;border:1px solid #CCC;background:#FFF;margin:5px;padding:2px;font-weight:bold;} .sd02{cursor:pointer;border:0px solid #CCC;margin:5px;padding:2px;} --> </style> <script type="text/javascript"> /* 十三妖 qq:181907667 msn:wl181907667@hotmail.com 邮箱:thirdteendevil@163.com */ function dragClass(){ this.mouseState = document.all ? 1 : 0 ; this.x; this.y; this.dragId = null; this.index = 100; document.onselectstart = function(){return false;}; } dragClass.prototype = { dragStar:function(dragId,moveId){//拖动入口函数 var _this = this; _this.$(dragId).style.cursor = "move"; _this.$(dragId).onmousedown = function(e){ var e = e ? e : event; //_this.$(moveId).style.zIndex = _this.index++; if(e.button == _this.mouseState) { _this.setDragInfo(e,moveId,moveId); _this.dragPro(moveId); } }, _this.$(moveId).onmousedown = function(e){ _this.$(moveId).style.zIndex = _this.index++; }, _this.$(dragId).onmouseup = function(){ _this.clearDragId(); } document.onmouseup = function(){ _this.clearDragId(); } }, setDragInfo:function(e,dragId,moveId){//拖动初始化 this.x = e.clientX; this.y = e.clientY; this.dragId = dragId; if(this.$(moveId).style.position != "absolute") { this.$(moveId).style.width = this.$(moveId).offsetWidth + "px"; this.$(moveId).style.height = this.$(moveId).offsetHeight + "px"; this.$(moveId).style.position = "absolute"; this.$(moveId).style.left = this.$(moveId).offsetLeft + "px"; this.$(moveId).style.top = this.$(moveId).offsetTop + "px"; } }, clearDragId:function(){ //清除拖动ID this.dragId = null; }, dragPro:function(moveId){ var _this = this; document.onmousemove = function(e){ var e = e ? e : event; if(e.button == _this.mouseState && _this.dragId != null) { var x = e.clientX; var y = e.clientY; //_this.$(moveId).style.left = (_this.$(moveId).offsetLeft + (x - _this.x)) + "px"; //_this.$(moveId).style.top = (_this.$(moveId).offsetTop + (y - _this.y)) + "px"; _this.$(moveId).style.left = (parseInt(_this.$(moveId).style.left) + (x - _this.x)) + "px"; _this.$(moveId).style.top = (parseInt(_this.$(moveId).style.top) + (y - _this.y)) + "px"; _this.x = x; _this.y = y; //alert(_this.$(dragId).style.left); } } }, $:function(o){//获取对象 if(typeof(o) == "string") { if(document.getElementById(o)) { return document.getElementById(o); } else { alert("errId \""+ o + "\"!"); return false; } } else { return o; } } } window.onload = function(){ var c = new dragClass(); c.dragStar("b","a"); c.dragStar("d","c"); } </script> </head> <body> <div class="bodyer"> <h1 class="t_rt"> 鼠标拖动层封装类 </h1> <h2> 效果预览 </h2> <div class="preview"> <div class="scrolldoorFrame"> <div id="a" style="width:200px;height:150px;background:#FFF;border:1px solid #DDD;"> <div id="b" style="height:20px;margin:1px;line-height:22px;overflow:hidden;background:#999;font-size:12px;font-weight:bold;color:#FFF;padding-left:15px;"> 拖动层1 </div> 移动层 </div> <div id="c" style="width:200px;height:150px;background:#FFF;border:1px solid #DDD;"> <div id="d" style="height:20px;margin:1px;line-height:22px;overflow:hidden;background:#999;font-size:12px;font-weight:bold;color:#FFF;padding-left:15px;"> 拖动层2 </div> 移动层 </div> </div> </div> <h2> 源代码 </h2> <div class="textDiv"> <textarea id="sourse"> function dragClass(){ this.mouseState = document.all ? 1 : 0 ; this.x; this.y; this.dragId = null; this.index = 100; document.onselectstart = function(){return false;}; } dragClass.prototype = { dragStar:function(dragId,moveId){//拖动入口函数 var _this = this; _this.$(dragId).style.cursor = "move"; _this.$(dragId).onmousedown = function(e){ var e = e ? e : event; //_this.$(moveId).style.zIndex = _this.index++; if(e.button == _this.mouseState) { _this.setDragInfo(e,moveId,moveId); _this.dragPro(moveId); } }, _this.$(moveId).onmousedown = function(e){ _this.$(moveId).style.zIndex = _this.index++; }, _this.$(dragId).onmouseup = function(){ _this.clearDragId(); } document.onmouseup = function(){ _this.clearDragId(); } }, setDragInfo:function(e,dragId,moveId){//拖动初始化 this.x = e.clientX; this.y = e.clientY; this.dragId = dragId; if(this.$(moveId).style.position != "absolute") { this.$(moveId).style.width = this.$(moveId).offsetWidth + "px"; this.$(moveId).style.height = this.$(moveId).offsetHeight + "px"; this.$(moveId).style.position = "absolute"; this.$(moveId).style.left = this.$(moveId).offsetLeft + "px"; this.$(moveId).style.top = this.$(moveId).offsetTop + "px"; } }, clearDragId:function(){ //清除拖动ID this.dragId = null; }, dragPro:function(moveId){ var _this = this; document.onmousemove = function(e){ var e = e ? e : event; if(e.button == _this.mouseState && _this.dragId != null) { var x = e.clientX; var y = e.clientY; //_this.$(moveId).style.left = (_this.$(moveId).offsetLeft + (x - _this.x)) + "px"; //_this.$(moveId).style.top = (_this.$(moveId).offsetTop + (y - _this.y)) + "px"; _this.$(moveId).style.left = (parseInt(_this.$(moveId).style.left) + (x - _this.x)) + "px"; _this.$(moveId).style.top = (parseInt(_this.$(moveId).style.top) + (y - _this.y)) + "px"; _this.x = x; _this.y = y; //alert(_this.$(dragId).style.left); } } }, $:function(o){//获取对象 if(typeof(o) == "string") { if(document.getElementById(o)) { return document.getElementById(o); } else { alert("errId \""+ o + "\"!"); return false; } } else { return o; } } } </textarea> </div> <h2> 使用方法 </h2> <div class="preview"> 1.把以上代码引进你的页面 <script type="text/javascript" src="dragClass.js"></script><br/> 2.在页面的"</body>"标签前加入以下代码:<br/> <div class="example"> <script type="text/javascript"><br/> window.onload = function(){<br /> var c = new dragClass();//创建对象<br /> c.dragStar("拖动id","移动层id");<br /> }<br/> </script> </div> 其中sd方法中的参数为:<br/> 参数一 "拖动id":鼠标经过时候鼠标样式变成移动样式模样的元素的id<br/> 参数二 "移动层id":即将移动的元素的id<br/> <span class="red">3.建议移动层是绝对定位(position:absolute;).</span> </div> </div> <div class="authorInfo"> <div class="cont"> 十三妖 ThirdteenDevil <br/> [qq:181907667] [msn:wl181907667@hotmail.com] [e-mail:thirdteendevil@163.com] </div> </div> </body> </html>
前一页:
兼容IE和FF的收藏本站、设为首页代码
后一页:
漂亮的页面loading等待页面特效(3)
相关阅读
奸商修改器 病毒篡改ThinkPad CPU信息
深山留言板过年回家效果
深山行者旅行社网站管理系统 v1.4
dw里面查找替换使用正则删除sqlserver里面的CONSTRAINT
一个美化了的alert效果,非常不错。
黑色精灵留言板模板
innerHTML动态改变ID的CSS样式表
aliyun阿里云续费域名优惠口令(注册、续费都可以使用)
更多信息>>
栏目类别选择
百度小程序开发
微信小程序开发
微信公众号开发
uni-app
asp函数库
ASP
DIV+CSS
HTML
python
更多>>
同类信息
jquery下拉到某个固定位置然后某些元素发生改变样式状态
canvas绘制的文字如何换行
兼容pc、移动端用js实现复制内容到剪切板(支持苹果safari浏览器)
js兼容多个浏览器右下角漂浮广告
兼容ie6+和火狐的禁止右键
做在线客服时,聊天窗口的div滚动条始终在底部
更多>>
最新添加文章
2026 aliyun阿里域名云注册续费优惠口令
dw里面查找替换使用正则删除sqlserver里面的CONSTRAINT
Android移动端自动化测试:使用UIAutomatorViewer与Selenium定位元素
抖音直播音挂载小雪花 懂车帝小程序
javascript获取浏览器指纹可以用来做投票
火狐Mozilla Firefox出现:无法载入您的Firefox配置文件 它可能已经丢失 或是无法访问 问题解决集合处理办法
在Android、iOS、Windows、MacOS中微信小程序的文件存放路径
python通过代码修改pip下载源让下载库飞起
更多>>
随机抽取信息
求实时获取两个input日期型值的差
旅行社网站模板9
网站需要SEO,基本的SEO建站要点
rs操作数据表记录集对象的方法
本站出现验证码问题
偏重于汽车租赁服务商建站解决方案
更多标签
热门标签
strong
Excel
页面
圆角
relative
滤镜
DOCTYPE
学习
li
Java
右击失效
html
文件类型
源码
详解
important
首字母
调色板
px
选择符
性能
多选框
载入
光标
Margin加倍
在线
链接样式
验证码
文字垂直
处理
理想
客户端
设为首页
自适应
Request
window
状态栏
数字
失效
商城
蓝色理想
button
动画
分页
eof
转换
open
正则
默认高度
动态
免责声明:本站所有资料信息,有部分为本人原创,部分为从网络收集而来,仅供网友查看阅读所用,所有信息版权归信息所有人或所有公司所有
如果信息内容侵犯到您的版权或权益请与我们联系,经确认后我们会立即移除相关内容或链接
Copyright © 2007-2026
深山工作室
All Rights Reserved
服务QQ:
565449214
手机:
13961347334
ICP备案:
苏ICP备15019627号
苏公网安备 32070502010230号