我的目标是通过组件属性提供过渡速度,并为增长和收缩设置不同的值。到目前为止,我设法通过以编程方式更改组件样式来实现这一点。
<script>
let isFullHeight = false
export let fullHeight = 400
export let growDurationMs = 1234
export let shrinkDurationMs = 567
</script>
<div id="container" style={isFullHeight ?
`height: ${fullHeight}px; transition: height ${growDurationMs}ms;` :
`transition: height ${shrinkDurationMs}ms;`}
on:click={() => isFullHeight = !isFullHeight}>
</div>
这可以完成这项工作,但也许有更惯用/优雅的方式来做到这一点。