使用 reverteffect 选项进行拖放

说明

此选项用于定义可拖动元素恢复到起始位置时使用的效果。

默认为平滑滑动到元素的原始位置。reverteffect 选项指定在 revert 选项设置为 true 时在 endeffect 函数之前调用的函数。

语法

new Draggable('element', {reverteffect: 'effectFunction'});

此处的 effectFunction 是定义要应用的效果的函数。

示例

<html>
   <head>
      <title>Draggables Elements</title>
		
      <script type = "text/javascript" src = "/javascript/prototype.js"></script>
      <script type = "text/javascript" src = "/javascript/scriptaculous.js"></script>
		
      <script type = "text/javascript">
         window.onload = function() {
            var img = 'myimage';
            new Draggable('myimage' , {
            revert: true,
            reverteffect: function(){
               new Effect.MoveBy('myimage', 100,100);
               }
            });
         }
      </script>
   </head>

   <body>
      <p>Drag and leave this image to see the result.</p>
      <img id = "myimage" src = "/images/scriptaculous.gif"/>
   </body>
</html>

这将产生以下结果 −

scriptaculous_drag_drop.html