uniapp抽屉滑动效果

typescript 复制代码
<template>
	<view class="content">
		<image class="logo" src="/static/logo.png"></image>
		<view class="text-area">
			<text class="title">{{title}}</text>
		</view>
	</view>
	<view class="button-group">
		<button type="primary" @click="toggleDrawer">登录</button>
	</view>

	<!-- 抽屉 -->
	<view v-if="drawerVisible" class="drawer">
		<view class="drawer-content">
			<text>这是抽屉的内容</text>
			<button @click="toggleDrawer">关闭</button>
		</view>
	</view>
</template>
<script>
	export default {
		data() {
			return {
				title: '',
				drawerVisible: false // 控制抽屉显示状态
			}
		},
		methods: {
			toggleDrawer() {
				this.drawerVisible = !this.drawerVisible;
			}
		}
	}
</script>

使用v-if判当前的drawerVisible状态

在js中先初始化为false

下面是CSS代码

css 复制代码
.content {
		display: flex;
		flex-direction: column;
		align-items: center;
		justify-content: center;
		flex: 1; /* 使content占据剩余空间 */
	}

	.logo {
		height: 200rpx;
		width: 600rpx;
		margin-top: 200rpx;
		margin-left: auto;
		margin-right: auto;
		margin-bottom: 50rpx;
	}

	.text-area {
		display: flex;
		justify-content: center;
	}

	.title {
		font-size: 36rpx;
		color: #8f8f94;
	}

	.button-group {
		position: fixed;
		width: 100%;
		bottom: 150rpx;
		display: flex;
		justify-content: center;
	}

	button {
		width: 60%;
	}

	/* 抽屉背景遮罩 */
	.drawer {
		position: fixed;/*固定*/
		left: 0;
		right: 0;
		bottom: 0;
		top: 0;
		background-color: rgba(0, 0, 0, 0.5);
		display: flex;
		justify-content: center;
		align-items: flex-end;/*将内容垂直对齐到容器的底部,使抽屉从底部弹出*/
		z-index: 1000;/*将元素前移*/
		animation: fadeIn 0.3s ease;/*0。3秒淡入显示*/
	}

	/* 抽屉内容 */
	.drawer-content {
		background-color: #fff;
		width: 100%;
		padding: 20rpx;
		border-top-left-radius: 20rpx;
		border-top-right-radius: 20rpx;
		box-shadow: 0 -2px 10px rgba(0, 0, 0, 0.1);
		animation: slideUp 0.3s ease;/*应用slideUp动画,使抽屉内容区域在0.3秒内从底部滑入应用slideUp动画,使抽屉内容区域在0.3秒内从底部滑入*/
	}

	/* 淡入效果 */
	@keyframes fadeIn {
		from {
			opacity: 0;/*动画开始时,元素的透明度为0(完全透明)*/
		}
		to {
			opacity: 1;
		}
	}

	/* 滑入效果 */
	@keyframes slideUp {
		from {
			transform: translateY(100%);
		}
		to {
			transform: translateY(0);
		}
	}

	/* 滑出效果 */
	@keyframes slideDown {
		from {
			transform: translateY(0);
		}
		to {
			transform: translateY(100%);
		}
	}
相关推荐
2501_915921435 小时前
小团队如何高效完成 uni-app iOS 上架,从分工到工具组合的实战经验
android·ios·小程序·uni-app·cocoa·iphone·webview
2501_916008897 小时前
uni-app iOS 文件管理与 itools 配合实战,多工具协作的完整流程
android·ios·小程序·https·uni-app·iphone·webview
!win !8 小时前
uni-app项目Tabbar实现切换icon动效
小程序·uni-app
xw58 小时前
uni-app项目Tabbar实现切换icon动效
前端·uni-app
2501_916007479 小时前
uni-app iOS 文件调试常见问题与解决方案:结合 itools、克魔、iMazing 的实战经验
android·ios·小程序·https·uni-app·iphone·webview
豆豆(设计前端)9 小时前
使用 Uni-app 打包 外链地址APK 及 iOS 注意事项
ios·uni-app
jingling5559 小时前
uniapp | 解决组件样式不生效问题
前端·css·uni-app·html·学习方法
^Rocky9 小时前
微信小程序(uniapp)实现连接蓝牙
微信小程序·uni-app·蓝牙连接
2501_9159184116 小时前
uni-app 项目 iOS 上架踩坑经验总结 从证书到审核的避坑指南
android·ios·小程序·https·uni-app·iphone·webview
游戏开发爱好者816 小时前
iOS 上架 uni-app 流程全解析,从打包到发布的完整实践
android·ios·小程序·https·uni-app·iphone·webview