css3過渡與動畫個人案例——彈入窗口

前言

變形、旋轉(zhuǎn)、轉(zhuǎn)換、過渡和動畫是現(xiàn)在前端必備的技能之一,也是為了更加便捷作出較為美觀的頁面。

因此個人會實踐日常工作可能實現(xiàn)的功能作為例子讓我們更加熟悉變形、旋轉(zhuǎn)、轉(zhuǎn)換、過渡和動畫。以下是兩者的相關(guān)敘述
CSS3動畫》、《CSS3過渡》、《CSS3變形、轉(zhuǎn)換、旋轉(zhuǎn)

現(xiàn)在我們來實現(xiàn)窗口彈入的過渡與動畫的案例,不喜歡樣式可以自己搭配,同時也希望大家能給點鼓勵或者提供需求。
1.gif

HTML

<div id="main">
  <button type="button" class="press">點擊彈出</button>
  <div id="contain">
    <button class="end">X</button>
  </div>
</div>

JS

let pre=document.querySelector(".press")//點擊按鈕
let end=document.querySelector(".end")//退出按鈕
pre.addEventListener("click",clickChange)
end.addEventListener("click",clickChange)
//點擊事件觸發(fā)方法,添加或刪除樣式
function clickChange(){
  let change=document.querySelector("#main").classList
  let contain=document.querySelector("#contain").classList
  change.contains("change")?  change.remove("change"):change.add("change")
  contain.contains("change")?contain.remove("change"):contain.add("change")
}

CSS

html,body{
padding: 0;
margin: 0;
}
body{
background-color: #C3BED4;
background-size: 100% 100%;
}
#main{
height: 100vh;/*取視高*/
display: flex;
justify-content: center;
align-items: center;
font-size: large;
font-family: "arial, helvetica, sans-serif";
color: #42B983;
}
#main.change::before {/*添加change樣式后的before偽元素,作為點擊后的背景陰影*/
content: "";
position: absolute;/*z-index必須有position:absolute*/
top: 0;
left: 0;
height: 100%;
width: 100%;
z-index: 100;
background-color: #fff;
animation:my-animation 1s ;/*定義動畫名稱和時長*/
opacity: 0.6;
}
@keyframes my-animation{/*動畫規(guī)則*/
from{
opacity: 0;
}
to{
opacity: 0.6;
}
}
.press{/*點擊按鈕的樣式*/
display: block;
width: 80px;
height: 30px;
border-radius: 10px;
background-color:#FFE4C4;
font-family: "arial black";
font-weight: bold;
color: #3079AB;
}
#contain{/*窗口的設(shè)定,此時的top為-50%*/
position: absolute;
z-index: 1000;
top: -50%;
left: 50%;
height: 200px;
width: 240px;
transform: translate(-50%,-50%);
background-color: #FD5B78;
border: solid #F7F7F7 6px;
border-radius: 10px;
display: flex;
flex-direction: row-reverse;
transition: top 1s;/*top的過渡*/
}
#contain.change{/*點擊按鈕添加樣式后的窗口樣式,top為50%*/
position: absolute;
z-index: 1000;
top: 50%;
left: 50%;
height: 200px;
width: 240px;
transform: translate(-50%,-50%);
background-color: #FD5B78;
border: solid #F7F7F7 6px;
border-radius: 10px;
display: flex;
flex-direction: row-reverse;
}
.end{
width: 30px;
height: 30px;
display: block;
border: solid #E9E9E9 2px;
background-color: #FA8072;
}
最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時請結(jié)合常識與多方信息審慎甄別。
平臺聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點,簡書系信息發(fā)布平臺,僅提供信息存儲服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

  • CSS參考手冊 一、初識CSS3 1.1 CSS是什么 CSS3在CSS2.1的基礎(chǔ)上增加了很多強(qiáng)大的新功能。目前...
    沒汁帥閱讀 4,291評論 1 13
  • 在AngularJS應(yīng)用中創(chuàng)建動畫,有三種途徑: 使用CSS3動畫 使用JavaScript動畫 使用CSS3過渡...
    oWSQo閱讀 1,564評論 0 3
  • 因為近期項目沒有壓力,主要工作就是一些涉及功能增刪相關(guān)的界面的小工作,修修補(bǔ)補(bǔ),搞個圖標(biāo)之類,設(shè)計師小伙伴們都懂的...
    泱泱悲秋閱讀 6,019評論 1 27
  • 一:在制作一個Web應(yīng)用或Web站點的過程中,你是如何考慮他的UI、安全性、高性能、SEO、可維護(hù)性以及技術(shù)因素的...
    Arno_z閱讀 1,369評論 0 1
  • 轉(zhuǎn)載自微信公眾號:百草園書店 湯湯|文 其實人生,就是一個不斷推翻過去,重新認(rèn)知世界的過程。 走著走著,我忽然明白...
    TiNY_FlorA閱讀 763評論 0 1

友情鏈接更多精彩內(nèi)容