网站首页
关于深山
客户案例
业务范围
联系深山
网络投票系统
企业网站建设
旅行社网站建设
小程序
留言板
技术文章
许愿墙(qq爱墙)
技术首页
百度小程序开发
微信小程序开发
微信公众号开发
uni-app
asp函数库
ASP
asp.net
DIV+CSS
HTML
SEO搜索引擎忧化
下载类信息
个人空间
代码生成
电商
python
页面特效
表格特效
导航菜单
图形特效
表单特效
时间日期
色彩类别
链接特效
网页特效
系统硬件
网站公告
网页学习
技术类文章
网站类信息
订阅本栏目 RSS
您所在的位置:
深山工作室
>
页面特效
> 正文
拖动效果 封装 已经修改,适应火狐
蓝色理想 2009/5/2 21:35:40 深山行者 字体:
大
中
小
浏览 12903
以下为详细代码
<!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)
相关阅读
windows xp 安装IIS,设置IIS。
CSS教程:CSS兼容的技巧
CSS代码格式化和压缩化
javascript正则的用法与示例
国内组团社旅游服务商建站解决方案
深山工作室
一个非常好的photoshop cs 教程下载地址
在服务器上新建网站,在服务器用域名能访问,但是外网访问不了的解决办法
更多信息>>
栏目类别选择
百度小程序开发
微信小程序开发
微信公众号开发
uni-app
asp函数库
ASP
DIV+CSS
HTML
python
更多>>
同类信息
jquery下拉到某个固定位置然后某些元素发生改变样式状态
canvas绘制的文字如何换行
兼容pc、移动端用js实现复制内容到剪切板(支持苹果safari浏览器)
js兼容多个浏览器右下角漂浮广告
兼容ie6+和火狐的禁止右键
做在线客服时,聊天窗口的div滚动条始终在底部
更多>>
最新添加文章
dw里面查找替换使用正则删除sqlserver里面的CONSTRAINT
Android移动端自动化测试:使用UIAutomatorViewer与Selenium定位元素
抖音直播音挂载小雪花 懂车帝小程序
javascript获取浏览器指纹可以用来做投票
火狐Mozilla Firefox出现:无法载入您的Firefox配置文件 它可能已经丢失 或是无法访问 问题解决集合处理办法
在Android、iOS、Windows、MacOS中微信小程序的文件存放路径
python通过代码修改pip下载源让下载库飞起
python里面requests.post返回的res.text还有其它的吗
更多>>
随机抽取信息
ASP.NET常用的三十三种实用代码(上)
重要声明:关于某些人冒充本网站。
一个简单的用java写的非常不错的贪食蛇游戏
解决国内 github.com 打不开的准确方法
在服务器上新建网站,在服务器用域名能访问,但是外网访问不了的解决办法
提交按钮在自定时间内灰色不可用
更多标签
热门标签
行号
统计
滑轮
边框
邮箱
二级
script
letter-spacing
拖动
div的高度
png24
创建
货币
FireFox
Excel
对象
创业
button
optgroup
网易
翻滚
锚点
下划线
右击
iis
CAD
考试
base
故事
名称
插件
资料
dt
变色
逗号
mop
显示
脚本
265
排序
图层
用户体验
层
固定
dreawmeaver
工作
小旋风
保护眼睛的电脑色
比例
filter
免责声明:本站所有资料信息,有部分为本人原创,部分为从网络收集而来,仅供网友查看阅读所用,所有信息版权归信息所有人或所有公司所有
如果信息内容侵犯到您的版权或权益请与我们联系,经确认后我们会立即移除相关内容或链接
Copyright © 2007-2026
深山工作室
All Rights Reserved
服务QQ:
565449214
手机:
13961347334
ICP备案:
苏ICP备15019627号
苏公网安备 32070502010230号