分享:代码非常简洁且兼容多浏览器的拖动层
2011-01-02 17:30
363 查看
<!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>代码非常简洁且兼容多浏览器的拖动层</title> </head> <body> <div id="f" style="position: absolute; width: 500px; height: 350px; background-color: #ccc; top: 150px; left: 200px; z-index: 101; border: solid 1px blue;"> <div id="title" style="background-color: Blue; cursor: move; height: 20px; color: #fff;font-size: 13px; padding-top: 5px; padding-left: 10px;">这里是层标题websjy.com</div> </div> <script type="text/javascript"> var posX; var posY; fdiv = document.getElementById("f"); document.getElementById("title").onmousedown=function(e) { if(!e) e = window.event; posX = e.clientX - parseInt(fdiv.style.left); posY = e.clientY - parseInt(fdiv.style.top); document.onmousemove = mousemove; } document.onmouseup = function() { document.onmousemove = null; } function mousemove(ev) { if(ev==null) ev = window.event; fdiv.style.left = (ev.clientX - posX) + "px"; fdiv.style.top = ev.clientY - posY + "px"; } </script> </body> </html>
查看演示效果
相关文章推荐
- 代码非常简洁且兼容多浏览器的拖动层实现代码
- 代码非常简洁且兼容多浏览器的拖动层实现代码
- 分享:代码简洁且兼容多种浏览器的拖动层
- Qt开发-简易浏览器+无边框阴影可移动可拖动窗口代码分享
- 分享一个css浏览器兼容重构代码
- 兼容ie6浏览器的php下载文件代码分享
- 兼容ie6浏览器的php下载文件代码分享
- 用Meta标签代码让360双核浏览器默认极速模式打开网站不是兼容模式(顺带解决很多兼容性问题)
- 设为首页加入收藏代码_兼容各浏览器ie系列Firefox
- jquery iframe自适应高度代码(浏览器兼容)
- 加入收藏、设为首页代码,兼容360/火狐/谷歌/IE等主流浏览器
- 加入收藏js代码 兼容所有浏览器
- JS获取按键的代码,Js如何屏蔽用户的按键,Js获取用户按键对应的ASII码(兼容所有浏览器)
- 网站哀悼变灰代码集合 兼容所有浏览器的CSS变暗代码
- JS实时显示当前时间(IE+firefox)浏览器兼容代码(图证)
- 文本框中,回车键触发事件的js代码[多浏览器兼容]
- 一个多浏览器支持的背景变暗的div并可拖动提示窗口功能的代码
- 添加到收藏夹代码(兼容几乎所有的浏览器)
- 一款非常实用的在线代码分享站点
- 使用Mootools动态添加Css样式表代码,兼容各浏览器