动画方法返回Promise对象

pull/1/head 1.8.3
yutent 2023-04-04 13:55:01 +08:00
parent 724b3732a0
commit 0ee7ddc6a1
4 changed files with 9 additions and 6 deletions

View File

@ -1,6 +1,6 @@
{
"name": "@bd/core",
"version": "1.8.2",
"version": "1.8.3",
"type": "module",
"description": "百搭UI组件库的核心",
"main": "dist/index.js",

View File

@ -13,15 +13,18 @@ export function animate(duration = 200, fromto = [], out = false) {
direction: out ? 'reverse' : 'normal',
fill: 'forwards'
})
if (out) {
return new Promise(resolve => {
res.addEventListener(
'finish',
_ => {
if (out) {
this.style.display = 'none'
}
resolve()
},
{ once: true }
)
}
})
}
export const MODES = {
fade: [{ opacity: 0 }, { opacity: 1 }],

View File

@ -631,7 +631,7 @@ class AnimPart extends AttributePart {
fromto = custom
}
this.element.$animate = function (out = false) {
animate.call(this, duration, fromto, out)
return animate.call(this, duration, fromto, out)
}
}
}

View File

@ -91,7 +91,7 @@ export class Component extends HTMLElement {
Object.defineProperty(this.prototype, '$animate', {
value(out) {
if (this[__mounted__]) {
animate.call(this, duration, MODES[type], out)
return animate.call(this, duration, MODES[type], out)
}
},
enumerable: false