【问题标题】:FramerJS: Reordering an arrayFramerJS:重新排序数组
【发布时间】:2015-02-13 10:39:50
【问题描述】:

我的母语不是英语,对不起我的台词。

我做了这样的数组..

# item layers
a = new Layer({x:20, width:80, height:80, image:"images/a.png"})
b = new Layer({x:120, width:80, height:80, image:"images/b.png"})
c = new Layer({x:220, width:80, height:80, image:"images/c.png"})
d = new Layer({x:320, width:80, height:80, image:"images/d.png"})
e = new Layer({x:420, width:80, height:80, image:"images/e.png"})
f = new Layer({x:520, width:80, height:80, image:"images/f.png"})

# item layers array - draggable
item = [a, b, c, d, e, f]
for i in [0..5] 
	item[i].draggable.enabled = true
	item[i].draggable.speedY = 0
	item[i].borderRadius = 100
	item[i].opacity = 0.5
	item[i].centerY()	

# item reorder
item[i].on Events.DragMove, ->
   if item[i].midX > item[i+1].midX
      item[i+1].animate
          properties:
             x:item[i+1].x - 100

   else if item[i].midX < item[i-1].midX
      item[i-1].animate
          properties:
             x:item[i-1].x + 100

但它不起作用。 拖动图层a时,其他图层不移动。 我该如何解决??

【问题讨论】:

  • 不清楚您要达到什么目标以及问题是什么。
  • 根据 FramerJS / Framer Studio 提问的最佳方式是我们专门的 Facebook 群组:facebook.com/groups/framerjs

标签: javascript arrays coffeescript framerjs


【解决方案1】:

通过i 访问图层,但i 在事件中始终为6,因为i 引用了相同的事物(在内存中)。您可以像这样在每个循环上“捕获”图层。

prev = item[i-1] if i > 0
curr = item[i]
next = item[i+1] if i<item.length-1

但问题仍然存在。第一次订购会很好。但第二个不会像你想要的那样工作。动画中的属性应在订购后重新计算。这听起来很疯狂?好吧。按位置访问比按数组索引更好。 like this,你懂的。

【讨论】:

    猜你喜欢
    • 2011-01-27
    • 2012-08-11
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-02-14
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多