这个JS控制的可以随意拖动的层在IE6和7中正常,在FF和GG中不能动 用jquery实现非常简单可google “jquery 拖动” 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 我找到一个 http://dev.iceburg.net/jquery/jqDnR/ 但是还是不知道怎么用 obj_Ofx = event.clientX; 你的不兼容就是类似这个几个地方不兼容event在FF中读取不到的 http://dev.iceburg.net/jquery/jqDnR/ 的效果不太合适,我要的是原来的效果4楼的朋友,这个代码要怎么改呢?谢谢 找到一个,效果很好!--------------------------------------------共享一个简单的JS拖动层效果,支持ie,ff,opera,safari;ie有专门的拖动方法:dragstart,drag,dragend分别是开始拖动,拖动,结束拖动。但是其他浏览器(dom类,例如ff)不支持这些拖动方法。所以只能用鼠标事件模拟拖动层效果。实现原理:我们知道用户使用拖动效果,需要完成一下事件1.在某个区域按下鼠标左键,2.按住鼠标左键不放,拖动鼠标;3.拖到合适的位置后,放开鼠标左键。这3步用JS的事件来描述的话就是:用户在可拖动区域onmousedown,并在onmousedown的情况下触发onmousemove事件,当onmouseup的时候移除onmousemove事件。看代码:=============================================================================<!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=utf-8" /><title>无标题文档</title></head><body><div id="f" style="position: absolute; width: 200px; height: 150px; 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;"> 拖动层 </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; //如果是IE 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;//如果是IE fdiv.style.left = (ev.clientX - posX) + "px"; fdiv.style.top = (ev.clientY - posY) + "px";}</script></body></html> Extjs4.0 如何遍历grid行? 求一段简单js的图片轮播演示代码 DIV与JAVASCRIPT问题,请教 js字符串分割问题 如何用javascript获得上个页面传入的变量? 散分一百 如何实现只要单击超连接所在行,就可以实现画面转移? 急急急!!! 在web开发中,如何在html或javascript代码(客户端)得到当前域名,?送分 未知当前表单名及文本框名时如何将焦点定位在页面的第一个文本框? 问个幼稚的问题,鼠标双击事件是什么,怎么ondbclick不灵。 100分 JavaScript 计算一个月有几周?? 急 怎么将简体页面转换成繁体页面
你的不兼容就是类似这个几个地方不兼容event在FF中读取不到的
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>无标题文档</title>
</head><body>
<div id="f" style="position: absolute; width: 200px; height: 150px; 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;"> 拖动层 </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; //如果是IE
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;//如果是IE
fdiv.style.left = (ev.clientX - posX) + "px";
fdiv.style.top = (ev.clientY - posY) + "px";
}
</script></body>
</html>