animateInView()

如果 draggable 位于容器之外,则将其动画移动到视口内。

参数

名称 类型 描述
duration(可选) 数字 动画的持续时间(默认 350
gap(可选) 布尔值 draggable 动画移动到容器边缘时应保持的额外间距
ease(可选) ease 应用于动画的缓动函数(默认 InOutQuad

返回

可拖动元素本身

animateInView() 代码示例

import { createDraggable, utils } from 'animejs';

const [ $animateInView ] = utils.$('.animate-button');

const draggable = createDraggable('.square', {
  container: '.grid',
});

const animateInView = () => {
  draggable.animateInView(400, 16);
}

// Set the draggable position outside the container
draggable.x = -24;
draggable.y = 72;

$animateInView.addEventListener('click', animateInView);
<div class="medium padded show-bounds grid square-grid animate-in-view">
  <div class="square draggable"></div>
</div>
<div class="large row">
  <fieldset class="controls">
    <button class="button animate-button">Animate in view</button>
  </fieldset>
</div>
.show-bounds.grid.square-grid.animate-in-view::after {
  opacity: 1;
  top: calc(1rem);
  right: calc(1rem - 1px);
  bottom: calc(1rem - 1px);
  left: calc(1rem);
  border: 1px dashed currentColor;
  box-shadow: none;
}