javascript - Vue 动画是即时的(无持续时间)
问题描述
我完全根据文档创建了 Vue 动画:
transition
组件有name="fade"
属性v-if
在孩子的transition
- 样式是从文档中复制的
new Vue({
el: '#app',
template: `
<transition name="fade">
<div
class="NotificationBar"
v-if="show"
:class="{
NotificationBar__Success: currentNotificationType === notificationBarTypes.success
}"
@click="show = !show"
>
<div class="NotificationBar-Centerer">
<svg class="NotificationBar-Icon-SvgCanvas" viewBox="0 0 24 24">
<path class="NotificationBar-Icon-SvgPath" v-if="currentNotificationType === notificationBarTypes.success" d="M12 2C6.5 2 2 6.5 2 12S6.5 22 12 22 22 17.5 22 12 17.5 2 12 2M10 17L5 12L6.41 10.59L10 14.17L17.59 6.58L19 8L10 17Z"></path>
</svg>
<div class="NotificationBar-Text">{{ message }}</div>
</div>
</div>
</transition>
`,
data: {
show: true,
currentNotificationType: 'success',
message: 'OK',
notificationBarTypes: {
success: 'success'
}
}
})
在样式中,我设置了 10 个进行实验:
.fade-enter-active, .fade-leave-active {
transition: opacity 10s;
}
.fade-enter, .fade-leave-to {
opacity: 0;
}
不知何故动画是即时的(持续时间为 0s)。
请检查 JSFiddle 以获取工作示例。
解决方案
您错误地将选择器嵌套在内部.NotificationBar
(在 SCSS 中)。确保您的选择器没有嵌套,以便正确应用样式。
// Do not nest these inside another selector, or make sure
// whatever selector you use here will apply to your element
.fade-enter-active, .fade-leave-active {
transition: opacity 10s;
}
.fade-enter, .fade-leave-to {
opacity: 0;
}
推荐阅读
- ubuntu - 如何在 ROS 凉亭中加载 kuka iiwa R820?
- swift - 使用 Swift 取消选择任务控制上的窗口
- python - 如何使用 Miniconda 创建纯 Python 虚拟环境?
- laravel-blade - 使用刀片 (Livewire) 调用动态内容
- lua - 如何在 ROBLOX 中找到零件表面的 2D 区域?
- td-engine - 使用TDengine时如何知道表在哪个vnode?
- flutter - 为什么有时我不能在 dart 文件中使用术语,而在其他 dart 文件中我可以使用该术语?
- c# - 我需要添加什么来使用 LineCounter 为 textBox1 输入自动更新 textBox2?
- r - 过滤条件,除了指定行给定行索引号 dplyr
- python - 从导入的模块查询数据库时出错