分享:代码简洁且兼容多种浏览器的拖动层
2011-01-02 17:32
465 查看
<!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>
查看演示效果
相关文章推荐
- 分享:代码非常简洁且兼容多浏览器的拖动层
- 代码非常简洁且兼容多浏览器的拖动层实现代码
- 代码非常简洁且兼容多浏览器的拖动层实现代码
- 原生JavaScript拖动div兼容多种浏览器
- js框架jquery实现幸运大转盘抽奖程序代码,兼容多种浏览器
- 分享一个css浏览器兼容重构代码
- 兼容ie6浏览器的php下载文件代码分享
- 兼容ie6浏览器的php下载文件代码分享
- js框架jquery实现幸运大转盘抽奖程序代码,兼容多种浏览器
- Qt开发-简易浏览器+无边框阴影可移动可拖动窗口代码分享
- 编写跨浏览器兼容的 CSS 代码的金科玉律
- 设为首页,加入收藏兼容360/火狐/谷歌/IE等主流浏览器的代码
- 浏览器兼容CSS代码:按钮文字垂直居中(input button text vertical align)
- 分享10个帮助你编写更加简洁javascript代码的小技巧
- js复制网页内容并兼容各主流浏览器的代码
- JS实时显示当前时间(IE+firefox)浏览器兼容代码(图证)
- 编写跨浏览器兼容的 CSS 代码的金科玉律
- 兼容所有浏览器的js关闭当前网页代码
- 360兼容模式 IE8等 从代码中屏蔽 通知栏弹出“浏览器已经限制此文件显示可能访问您的计算机的活动内容”
- 简洁短小的 JavaScript IE 浏览器判定代码