Example: Interactions

Let's create a simple draggable interaction within a module. In our myModule.coffee file, we include the following function. It takes a layer, makes it draggable, and snaps it back to its original position on DragEnd.
译:导航到模块文件夹,然后打开程序目录既。coffee的文本编辑器中的文件。
让我们创建一个简单的拖动在一个模块内的相互作用。在我们的程序目录既。 咖啡文件,包括以下功能。它需要一层,使它可拖动和快照DragEnd回其原始位置。

# A draggable function without our module 
exports.makeDraggable = (layer) ->
    layer.draggable.enabled = true

    # Store current x and y position 
    startX = layer.x
    startY = layer.y

    # Animate back on DragEnd 
    layer.on Events.DragEnd, ->
        this.animate
            properties:
                x: startX
                y: startY
            curve: "spring(300,20,0)"

Now, within our prototype, we can call the makeDraggable function from our module to include the dragging interaction.
译:现在,在我们的原型,我们可以调用makeDraggable函数从我们的模块,包括拖放交互。

# Include module 
module = require "myModule"

# Set background 
bg = new BackgroundLayer
    backgroundColor: "#28AFFA"

# Create a new layer 
layerA = new Layer
    backgroundColor: "#fff"
    borderRadius: 4

layerA.center()

# Add the dragging interaction to layerA 
module.makeDraggable(layerA)

results matching ""

    No results matching ""