久久久精品一区ed2k-女人被男人叉到高潮的视频-中文字幕乱码一区久久麻豆樱花-俄罗斯熟妇真实视频

怎么使用純CSS實現(xiàn)飛機舷窗風(fēng)格的toggle控件

這篇文章主要介紹了怎么使用純CSS實現(xiàn)飛機舷窗風(fēng)格的toggle控件,具有一定借鑒價值,需要的朋友可以參考下。希望大家閱讀完這篇文章后大有收獲。下面讓小編帶著大家一起了解一下。

創(chuàng)新互聯(lián)-專業(yè)網(wǎng)站定制、快速模板網(wǎng)站建設(shè)、高性價比吉木乃網(wǎng)站開發(fā)、企業(yè)建站全套包干低至880元,成熟完善的模板庫,直接使用。一站式吉木乃網(wǎng)站制作公司更省心,省錢,快速模板網(wǎng)站建設(shè)找我們,業(yè)務(wù)覆蓋吉木乃地區(qū)。費用合理售后完善,10多年實體公司更值得信賴。

效果預(yù)覽

怎么使用純CSS實現(xiàn)飛機舷窗風(fēng)格的toggle控件

源代碼下載

https://github.com/comehope/front-end-daily-challenges

代碼解讀

定義 dom,.windows 容器表示舷窗,它的子元素 .curtain 表示窗簾:

<figure class="window">
    <div class="curtain"></div>
</figure>

居中顯示:

body {
    margin: 0;
    height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    background-color: skyblue;
}

設(shè)置舷窗的尺寸,因為后面還會用到字號,所以字號用變量定義:

:root {
    --font-size: 10px;
}

.window {
    position: relative;
    box-sizing: border-box;
    width: 25em;
    height: 35em;
    font-size: var(--font-size);
    background-color: #d9d9d9;
}

用陰影畫出厚窗框:

.window {
    border-radius: 5em;
    box-shadow: 
        inset 0 0 8em rgba(0, 0, 0, 0.2),
        0 0 0 0.4em #808080,
        0 0 0 4em whitesmoke,
        0 0 0 4.4em #808080,
        0 2em 4em 4em rgba(0, 0, 0, 0.1);
}

設(shè)置窗簾樣式,和窗口尺寸一樣,但不拉到底:

.window .curtain {
    position: absolute;
    width: inherit;
    height: inherit;
    border-radius: 5em;
    box-shadow:
        0 0 0 0.5em #808080,
        0 0 3em rgba(0, 0, 0, 0.4);
    background-color: whitesmoke;
    left: 0;
    top: -5%;
}

用偽元素在窗簾上畫出指示燈,當(dāng)窗簾關(guān)閉時亮紅色光:

.window .curtain::before {
    content: '';
    position: absolute;
    width: 40%;
    height: 0.8em;
    background-color: #808080;
    left: 30%;
    bottom: 1.6em;
    border-radius: 0.4em;
}

.window .curtain::after {
    content: '';
    position: absolute;
    width: 1.6em;
    height: 0.8em;
    background-image: radial-gradient(orange, orangered);
    bottom: 1.6em;
    border-radius: 0.4em;
    left: calc((100% - 1.6em) / 2);
}

以上是舷窗關(guān)閉時的樣子,接下來繪制舷窗打開時的效果。
先在 dom 中添加一個 checkbox,當(dāng)它被 checked 時即表示舷窗被打開:

<input type="checkbox" class="toggle">
<figure class="window">
    <div class="handle"></div>
</figure>

隱藏 checkbox,用 opacity(0) 可以使元素在不可見的狀態(tài)下仍可交互,把它的尺寸設(shè)置得到舷窗一樣大,并且圖層在舷窗之上,得到的效果就是點擊舷窗時實際是點擊了 checkbox

.toggle {
    position: absolute;
    filter: opacity(0);
    width: 25em;
    height: 35em;
    font-size: var(--font-size);
    cursor: pointer;
    z-index: 2;
}

當(dāng)舷窗打開時,.curtain 要向上移動,并且指示燈亮綠色光:

.window .curtain {
    transition: 0.5s ease-in-out;
}

.toggle:checked ~ .window .curtain {
    top: -90%;
}

.toggle:checked ~ .window .curtain::after {
    background-image: radial-gradient(lightgreen, limegreen);
}

隱藏超出窗戶的部分:

.window {
    overflow: hidden;
}

接下來繪制舷窗外的風(fēng)景。
在 dom 中增加表示云朵的 .clouds 元素,其中的 5 個 <span> 子元素分別表示 1 朵白云:

<input type="checkbox" class="toggle">
<figure class="window">
    <div class="curtain"></div>
    <div class="clouds">
        <span></span>
        <span></span>
        <span></span>
        <span></span>
        <span></span>
    </div>
</figure>

用云朵容器畫出窗外的藍天:

.window .clouds {
    position: relative;
    width: 20em;
    height: 30em;
    background-color: deepskyblue;
    box-shadow: 0 0 0 0.4em #808080;
    left: calc((100% - 20em) / 2);
    top: calc((100% - 30em) / 2);
    border-radius: 7em;
}

每朵云由 3 部分組成,先畫面積最大的部分:

.clouds span {
    position: absolute;
    width: 10em;
    height: 4em;
    background-color: white;
    top: 20%;
    border-radius: 4em;
}

再用偽元素畫 2 個突起的圓?。?/p>

.clouds span::before,
.clouds span::after {
    content: '';
    position: absolute;
    width: 4em;
    height: 4em;
    background-color: white;
    border-radius: 50%;
}

.clouds span::before {
    top: -2em;
    left: 2em;
}

.clouds span::after {
    top: -1em;
    right: 1em;
}

增加云朵飄動的動畫效果:

.clouds span {
    animation: move 4s linear infinite;
}

@keyframes move {
    from {
        left: -150%;
    }

    to {
        left: 150%;
    }
}

使每朵云的大小、位置有一些變化:

.clouds span:nth-child(2) {
    top: 40%;
    animation-delay: -1s;
}

.clouds span:nth-child(3) {
    top: 60%;
    animation-delay: -0.5s;
}

.clouds span:nth-child(4) {
    top: 20%;
    transform: scale(2);
    animation-delay: -1.5s;
}

.clouds span:nth-child(5) {
    top: 70%;
    transform: scale(1.5);
    animation-delay: -3s;
}

最后,隱藏容器外的內(nèi)容:

.window .clouds {
    overflow: hidden;
}

感謝你能夠認(rèn)真閱讀完這篇文章,希望小編分享怎么使用純CSS實現(xiàn)飛機舷窗風(fēng)格的toggle控件內(nèi)容對大家有幫助,同時也希望大家多多支持創(chuàng)新互聯(lián),關(guān)注創(chuàng)新互聯(lián)行業(yè)資訊頻道,遇到問題就找創(chuàng)新互聯(lián),詳細(xì)的解決方法等著你來學(xué)習(xí)!

新聞標(biāo)題:怎么使用純CSS實現(xiàn)飛機舷窗風(fēng)格的toggle控件
網(wǎng)站網(wǎng)址:http://sd-ha.com/article16/jsjegg.html

成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供建站公司、標(biāo)簽優(yōu)化網(wǎng)站導(dǎo)航、網(wǎng)站建設(shè)、小程序開發(fā)網(wǎng)頁設(shè)計公司

廣告

聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請盡快告知,我們將會在第一時間刪除。文章觀點不代表本網(wǎng)站立場,如需處理請聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時需注明來源: 創(chuàng)新互聯(lián)

搜索引擎優(yōu)化