在拖动< div>时,如何检测到我正在移动的内容? [英] when draging a <div>, how can I detect what I'm moving over?

查看:57
本文介绍了在拖动< div>时,如何检测到我正在移动的内容?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在玩可拖动的< DIV> s,受到google.com/ig的启发,

,您可以在页面上移动项目并移动项目
如果需要,可以在
更换位置。


我有3个div设置,每个可拖动项目一个(关于

100x150px的方框)在另一个设置边框的div里面。


我的脚本是由onMouseOver事件发起的,非常适合

移动项目,设置不透明度等等唯一的麻烦是(而且我估计我应该预料到这一点)就是当我拖动一个div时,

其他2个div的onMouseOver事件没有初始化。在

回顾这可能是一件好事,或者我最终会同时拖动

所有东西。


我正在寻找的是一个想法,去哪里找到

我拖着一个div。我故意不包含任何代码

我真的只是寻找提示而不是解决方案,因为这个

项目对我自己来说是一个学习练习,我已经通过下载dom-drag.js作为基本代码来充分骗取了b $ b。


任何想法我怎么能找到我的东西拖着过来?我的想法是

听众(虽然我对他们了解不多,但他们似乎在这里感觉很好)或者不担心我已经结束了,但更多的地方我在

列表然后解决,如果需要移动的东西(似乎

繁琐,可能是资源占用我检查鼠标移动

和拖动时的位置)


任何提示和/或提示都将受到赞赏。

解决方案

Kevin Blount写道:

我正在寻找的是一个想法,去哪里找出来我的意思我拖着一个div。我故意没有包含任何代码,因为
我真的只是寻找提示而不是解决方案,因为这个
项目对我自己来说是一个学习练习,而且我已经<通过下载dom-drag.js作为基本代码来欺骗足够的。




我真的很喜欢你的态度:)但是,它并没有伤害

阅读其他人的源代码,相反它可以帮助你理解

自己写,也许更好。


查看` IE的ondragover''事件处理程序:


< http://msdn.microsoft.com/workshop/author/dhtml/reference/events/ondragover.asp>


我不知道Gecko DOM是否也支持它,可能

不是因为引用没有提到它。但是,有一些

onmouse *事件处理程序可能并且可能用于此。


< http://developer.mozilla.org / en / docs / DOM:element#Event_Handlers>

HTH


PointedEars


谢谢响应..我肯定会看看ondragover ..

听起来很理想(虽然还没有确切知道它到底是什么< g>),并且谢谢

对于DOM引用也是如此。


>我真的很喜欢你的态度:)但是,对于

读取其他人的源代码并没有什么坏处,相反它可以帮助你理解自己编写它,可能更好。



这是一个非常艰难的行为,非常危险,我已经尝试了三次到目前为止看待它。


任何人都有任何类型的JavaScript重新格式化程序或pritty打印机?


我会在某个时候有另一个屠夫。


Aaron


I''m playing with dragable <DIV>s, being inspired by google.com/ig,
where you can move items on the page around and have items you move
over change position if necessary.

I have 3 div''s setup, one for each dragable item (boxes about
100x150px), inside another div that sets up a border.

my script is instigated by an onMouseOver event and works great for
moving items, setting the opacity, etc. The only trouble is (and I
guess I should have expected this) is that when I''m dragging one div,
the onMouseOver events for the other 2 divs are not initialized. In
retrospect that''s probably a good thing, or I''d end up dragging
everything at the same time.

What I''m looking for is an idea where to go next in order to find out
what I''m dragging a div over. I purposely didn''t include any code as
I''m really looking for just hints rather than solutions, as this
project is very much a learning excercise for myself, and I''ve already
cheated enough by downloading dom-drag.js as the base code.

any ideas how I can find out what I''m dragging over? My thoughts were
listeners (though I don''t know much about them but they seemed to make
sense here) or not worrying about what I''m over, but more where I am in
the list and then work out if something needs to be move or not (seems
cumbersome and potentially a resource hog while I check mouse movements
and positions while dragging)

any hints and/or tips would be appreciated.

解决方案

Kevin Blount wrote:

What I''m looking for is an idea where to go next in order to find out
what I''m dragging a div over. I purposely didn''t include any code as
I''m really looking for just hints rather than solutions, as this
project is very much a learning excercise for myself, and I''ve already
cheated enough by downloading dom-drag.js as the base code.



I really like your attitude :) However, it does not hurt to
read source code of others, instead it helps you to understand
to write it yourself, and probably better.

Look into the `ondragover'' event handler for IE:

<http://msdn.microsoft.com/workshop/author/dhtml/reference/events/ondragover.asp>

I don''t know if it is supported in the Gecko DOM as well, probably
not as the reference does not mention it. However, there are the
onmouse* event handlers which could be and are probably used for this.

<http://developer.mozilla.org/en/docs/DOM:element#Event_Handlers>
HTH

PointedEars


thanks for the response.. I''ll definitely check out the ondragover..
sounds ideal (though no clue exactly what it does yet <g>), and thanks
for the DOM references too.


> I really like your attitude :) However, it does not hurt to

read source code of others, instead it helps you to understand
to write it yourself, and probably better.



Its a pritty tough act to follow, very criptic, I''ve tried three times to
look at it so far.

Anyone got a JavaScript reformatter or pritty printer of any kind ?

I''ll have another butchers at it at some point.

Aaron


这篇关于在拖动&lt; div&gt;时,如何检测到我正在移动的内容?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆