vue+transition+opacity实现淡入淡出、过度、透明度

78 篇文章 1 订阅
71 篇文章 0 订阅


1、HTML部分

<div id="app">
	<div class="transition-box">
		<div :class="{transition: true, 'is-show': isShow}" @click="clickSwitch">
			<span style="font-size: 27px; font-weight: 700;">点击切换</span>
		</div>
	</div>
</div>

以上代码需要引入以下文件:
1、<link rel="stylesheet" href="./index.css">
2、<script src="/node_modules/vue/dist/vue.js"></script>
3、<script src="./index.js"></script>


2、JavaScript部分

new Vue({
	el: "#app",
    data() {
        return {
            isShow: false,
        }
    },

    methods: {
        clickSwitch() {
            this.isShow = !this.isShow;
        }
    }
});

3、css部分

.transition-box {
	width: 150px;
    display: flex;
    flex-direction: column;
    align-items: center;
}

.transition {
    width: 150px;
    height: 70px;
    line-height: 70px;
    text-align: center;
    background-color: #E6A23C;
    border-radius: 30px;
    cursor: pointer;
    /* 过度 */
    transition: all 1s;
    /* 透明度为0,完全透明 */
    opacity: .3;
}

.is-show {
    height: 150px;
    line-height: 150px;
    border-radius: 0;
    /* 透明度为1,就是不透明 */
    opacity: 1;
}

4、效果演示

4.1、微信小程序码

2.0.2X


4.2、普通二维码

2.0.2P


5、完整代码

gitee(码云) - develop分支 - fadeInFadeOut 文件夹

  • 17
    点赞
  • 14
    收藏
    觉得还不错? 一键收藏
  • 14
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 14
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值