手机端简单js点击实现上滑弹框的原生app效果

这个反正我也不知道怎么起名字,首先上效果图哈哈哈

嗯,就是这么简单的一个东西哈哈。下面上代码

<!DOCTYPE html>
<html lang="en">
<head>
	<meta charset="UTF-8">
	<meta name="viewport" content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0">
	<title>用户中心</title>
	<style>
		.test {
			width: 6.5714rem;
			height: 2.1429rem;
			line-height: 2.1429rem;
			margin: 0 auto;
			text-align: center;
			border: 0.0714rem solid gray;
			border-radius: 1rem;
		}
		.show {
			width: 85vw;
			height: 70vh;
			border: 0.0714rem solid lightgray;
			border-radius: 1rem;
			padding: 1rem 0.5rem;
			position: fixed;
			left: 1.15rem;
			bottom: -32rem;
			text-indent: 2rem;
			transition: bottom 1s ease;
			background-color: lightblue;
		}
	</style>
	<script src="https://code.jquery.com/jquery-3.4.1.min.js"></script>

</head>
<body>
	<div class="test">
		test
	</div>
	<div class="show">
		hello world
	</div>

	<script>
		$('.test').click(() => {
			$('.show')[0].style.cssText = 'bottom: -1rem; '
		});
		$('.show').click(() => {
			$('.show')[0].style.cssText = 'bottom: -32rem;'
		});
	</script>
</body>
</html>

还是老样子,取关键代码:

  1.             transition: bottom 1s ease;
  2.         $('.test').click(() => {
                $('.show')[0].style.cssText = 'bottom: -1rem; '
            }

好的那么整理一下就是:

first of all 将这个元素position属性设置为fixed,让其居于整个窗口最底部,且不能看到

In addition 为其设置transition过渡动画,我设置的是改变其bottom时,触发1s ease过渡类型的动画

finally 点击按钮时将show元素bottom设置为-1,让其从底部划出,模仿手机端原生效果。

嗯,今天好多事情,快要昏厥了,虽然这个很简单,不过我蛮喜欢的。哈哈哈,又快要到健身时间了。

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值