跳过主要内容

添加事件监听器

添加事件监听器( ) ;

细节

注册一个函数,每当发生特定类型的事件时调用该函数。在监听器函数内部,this指向触发事件的 Draggable 实例的目标。

事件

  • press(按下)
  • click(点击)
  • dragstart(拖动开始)
  • drag(拖动中)
  • dragend(拖动结束)
  • release(释放)
  • throwcomplete(抛掷完成)
  • throwupdate(抛掷更新)

用法

var myDraggable = Draggable.create("#box1", {  bounds: "#container"})[0];myDraggable.addEventListener("press", onPress);function onPress() {  console.log("myDraggable was pressed");  gsap.to(this, {duration: 0.2, backgroundColor: "red"}); // animate the backgroundColor of the target of the Draggable that was pressed}
无噪 Logo
无噪文档
中文文档 · 复刻官网
查看所有 ↗