拖动时的style.width问题 gg.parentNode.style.left = (e.clientX-tempx)+"px" gg.parentNode.style.top = (e.clientY-tempy)+"px"晕,你这2个!!!你自己测试就知道了一减看看是不是0,刚开始 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 offsetLeft是获取它与他的父节点之间的x..要获取它与window之间的x还的写函数..function offsety(s){nu=s.offsetLeftwhile(s.parentNode){s=s.parentNodeif(!isNaN(s.offsetLeft)){nu+=s.offsetLeft}}return nu}function offsetx(s){nu=s.offsetTopwhile(s.parentNode){s=s.parentNodeif(!isNaN(s.offsetTop)){nu+=s.offsetTop}}return nu}在你代码里调用 var tempx = e.clientX - offsetx(gg) var tempy = e.clientY - offsety(gg) <body><div style=" width:200px; height:190px; position:absolute;border:1px solid #666666"><div id="gg" style=" width:200px; height:40px; background:#FFFF99; "></div><div style=" width:200px; height:150px;"></div></div></body><script>var gg = document.getElementById("gg")gg.onmouseover = function(){ document.onmousedown =function(e) { e = e||event var tempx = e.clientX - gg.parentNode.offsetLeft var tempy = e.clientY - gg.parentNode.offsetTop document.onmousemove = function(e) { e = e||event gg.parentNode.style.left = (e.clientX-tempx)+"px" gg.parentNode.style.top = (e.clientY-tempy)+"px" } document.onmouseup = function () { document.onmousemove = null; document.onmouseup = null; } }}</script> 有什么可以代替event.currentTarget吗?IE不支持这个,火狐支持 EXTJS接收不到ASP.NET MVC返回的数据? 如何在JS里显示不同的弹出div层,同时JS里有弹出层的方法? 请问这段JS那有错,谢谢了 求一个JS 正则如何去除字符串中的HTML元素? 超级郁闷数据库连接问题,请高手看下,谢谢 用JavaScript获得服务器端的时间然后在另外的页面显示问题 如何点击按钮打开一个新的窗口(不要window.open()) 怎样设置网页不用缓存??每次都是最新的? 老大,看看这个语句为什么通不过 急求一个在js中字符串的替换
是获取它与他的父节点之间的x..
要获取它与window之间的x还的写函数..
function offsety(s){
nu=s.offsetLeft
while(s.parentNode){
s=s.parentNode
if(!isNaN(s.offsetLeft))
{nu+=s.offsetLeft}
}
return nu
}
function offsetx(s){
nu=s.offsetTop
while(s.parentNode){
s=s.parentNode
if(!isNaN(s.offsetTop))
{nu+=s.offsetTop}
}
return nu
}
在你代码里调用
var tempx = e.clientX - offsetx(gg)
var tempy = e.clientY - offsety(gg)
<div style=" width:200px; height:190px; position:absolute;border:1px solid #666666">
<div id="gg" style=" width:200px; height:40px; background:#FFFF99; "></div>
<div style=" width:200px; height:150px;"></div>
</div>
</body>
<script>
var gg = document.getElementById("gg")gg.onmouseover = function(){ document.onmousedown =function(e)
{
e = e||event
var tempx = e.clientX - gg.parentNode.offsetLeft
var tempy = e.clientY - gg.parentNode.offsetTop
document.onmousemove = function(e)
{
e = e||event
gg.parentNode.style.left = (e.clientX-tempx)+"px"
gg.parentNode.style.top = (e.clientY-tempy)+"px" }
document.onmouseup = function ()
{
document.onmousemove = null;
document.onmouseup = null;
}
}
}
</script>