0
我试图通过捕获鼠标坐标并相应地移动东西来将东西拖出我的文档。目前我使用document.addEventListener,即使我在窗口外面拖动东西,这也可以很好地工作。功能越来越多,为了跟上复杂性,我宁愿使用div和div1.addEventListener。我可以在文档窗口外面拖动元素,但不能在简单的div之外。为什么?
但是,这种改变不让我把东西拖到我的窗外,更不用说我的窗外了。我只是在谈论拖动(鼠标在div内,然后将鼠标拖出)。一旦我不在格子里,它就会刹车。
我不明白发生了什么,我很久以前就试验过它,并且我记得这是工作代码。
window.onload = function()
{
div1 = document.getElementById("div1");
document.addEventListener('mousedown', function(evt){mouseDown(evt, this)}, false);
document.addEventListener('mousemove', function(evt){mouseMove(evt, this)}, false);
document.addEventListener('mouseup', function(evt){mouseUp(evt, this)}, false);
// div1.addEventListener('mousedown', function(evt){mouseDown(evt, this)}, false);
// div1.addEventListener('mousemove', function(evt){mouseMove(evt, this)}, false);
// div1.addEventListener('mouseup', function(evt){mouseUp(evt, this)}, false);
}
function mouseMove(evt, caller)
{
}
function mouseDown(evt, caller)
{
}
function mouseUp(evt, caller)
{
}
但是,如果鼠标离开窗口,文档也是如此 – wubbewubbewubbe 2013-03-24 19:38:30
我不得不回头阅读规范,但我认为该窗口是一个特殊情况。根据您需要支持的浏览器,我建议您阅读HTML5拖放API。从长远来看,这可能会让你的生活变得更容易。 – Jerry 2013-03-24 19:45:52
HTML拖放是特别的东西。我不拖动HTML元素。我在画布上拖动形状。我想我应该早些时候提过。 – wubbewubbewubbe 2013-03-24 20:24:08