animateInView()
如果可拖动元素位于容器外部,则在视口内进行动画处理。
参数
| 名称 | 类型 | 描述 |
|---|---|---|
| duration(opt) | Number |
动画的持续时间(默认 350) |
| gap(opt) | Boolean |
可拖动元素应该被动画到距离容器边缘的额外距离是多少 |
| ease(opt) | 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;
}