我应该使用坐标来处理dropzone与draggabilly

时间:2014-10-29 09:24:45

标签: javascript coffeescript draggable droppable

我在项目中使用draggabilly来使一些元素可拖动。要知道元素何时在dropzone中,我使用带有拖动事件指针的getBoundingClientRect()

它给我这样的东西:

# I store boudings and element in an array
cards_bounding = []
matches = document.querySelectorAll("#board .card");
for match in matches
  bounding = match.getBoundingClientRect()
  cards_bounding.push(
    el: match
    bounding: 
      left: bounding.left
      right: bounding.right
      top: bounding.top
      bottom: bounding.bottom
  )

pointer_in_bounding = (pointer, bounding) ->
  bounding.left < pointer.pageX < bounding.right and bounding.top < pointer.pageY < bounding.bottom

# Then I check where is my pointer during the dragMove
drag_picked_card.on "dragMove", (draggieInstance, event, pointer) ->
  for card_bound in cards_bounding
    if pointer_in_bounding(pointer, card_bound.bounding)
      # …

这是实现这一目标的更好方法吗?

0 个答案:

没有答案