这个反正我也不知道怎么起名字,首先上效果图哈哈哈
嗯,就是这么简单的一个东西哈哈。下面上代码
<!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>
还是老样子,取关键代码:
- transition: bottom 1s ease;
- $('.test').click(() => {
$('.show')[0].style.cssText = 'bottom: -1rem; '
}
好的那么整理一下就是:
first of all 将这个元素position属性设置为fixed,让其居于整个窗口最底部,且不能看到
In addition 为其设置transition过渡动画,我设置的是改变其bottom时,触发1s ease过渡类型的动画
finally 点击按钮时将show元素bottom设置为-1,让其从底部划出,模仿手机端原生效果。
嗯,今天好多事情,快要昏厥了,虽然这个很简单,不过我蛮喜欢的。哈哈哈,又快要到健身时间了。