Q: 9月的最後一天来点特别的吧?
A: 常见的弹窗来一个!
首先来个简易的按钮.btn-open
来开启弹窗,然後在弹窗内有个关闭按钮可以关掉弹窗。
<style>
.btn-open {
width: 200px;
color: white;
line-height: 50px;
text-align: center;
background-color: brown;
border-radius: 10px;
cursor: pointer;
}
.container {
width: 320px;
border-radius: 10px;
overflow: hidden;
}
.title {
position: relative;
padding: 5px 0;
font-size: 30px;
text-align: center;
color: white;
background-color: DarkOrange;
}
.btn-close {
position: absolute;
top: 8px;
right: 10px;
font-size: 12px;
cursor: pointer
}
.content {
padding: 30px;
background-color: Bisque;
}
</style>
<div class="btn-open" onclick="addActive()">Open Popup</div>
<div id="container" class="container">
<div class="title">
Title
<div class="btn-close" onclick="removeActive()">Close</div>
</div>
<div class="content">Content</div>
</div>
再开启弹窗时在#container
新增.is-active
,而为了让弹窗弹出来时有Q弹的感觉,这里对弹窗下animation
。
<script>
function removeActive() {
document.getElementById('container').classList.remove('is-active')
}
function addActive() {
document.getElementById('container').classList.add('is-active')
}
</script>
<style>
.is-active.container {
animation: popup 0.5s;
}
@keyframes popup {
0% {transform: scale(0);}
20% {transform: scale(1.1);}
50% {transform: scale(0.95);}
80% {transform: scale(1.05);}
100% {transform: scale(1);}
}
</style>
对於弹窗来说比较常见的情况会是原本没有,在进行操作後显示,为了隐藏元素比较直觉会使用display: none
让元素不显示,但这里希望弹窗可以弹的美也缩的漂亮,改使用transform: scale(0)
将元素缩小至0倍,在画面上也就看不到啦!
<style>
.container {
transform: scale(0);
}
.is-active.container {
transform: scale(1);
}
</style>
当弹窗弹出时有animation
演绎弹出的效果,但当.is-active
被移除时,元素就是从transform: scale(1)
直接变成transform: scale(0)
,所以这时候如果也需要有缩小到不见的感觉时,最一开始使用的transition
就派上用场了。
<style>
.container {
transition: .1s;
}
</style>
今天介绍到这里~明天要来继续炸脑袋想灵感啦!
如果有写错的地方,欢迎点评! 会及时改进~
如果有更好的写法,欢迎指教! 希望各位不吝赐教~
如果想看更多效果,欢迎敲碗! 提供示意图小编写写看~
如果内容疑似侵权,拜托告知! 内容皆为小编理解後原创~
如果对你有点帮助,拿去用吧!
人的科技文明发展始终来自於人性 在现今的科技加速之下,所有的一切都将因为有了网路而有所不同,也因为在...
前言 今天读到Theme主题实作,刚好又是app主题色系变化。这次采用setTheme和Style来...
我们已经学会了运用画出图表的方式来检视模型的训练过程,有时候图表曲线所呈现的结果相当理想,和我们预想...
在 Angular 中 Dependency Injection 是个非常大的特点,Dependen...
接下来就从两大主题丰收款消费支付API与Shioaji证券API之间,挑一个来进行,既然证券开盘时间...