純CSS實現超酷發送按鈕

來源:互聯網
上載者:User

標籤:純css   css3 動畫   

前端開發whqet,csdn,王海慶,whqet,前端開發專家

今天在Dribble閑逛,偶然間看到一個不錯的發送完成效果,使用純css實現了下,最終效果如下。


----------------

----------------------------------------

線上研究點擊這裡,下載收藏點擊這裡。

----------------------------------------

---------------

製作這個案例,你需要擁有

1. Checkbox的:checked偽類類比實現CSS單擊事件

2. CSS3 transform和transition

3. 自行實現的衝動和耐心

好的言歸正傳,我們來一起實現一下。

html部分,我們需要使用label配合input[type="checkbox"]實現CSS單擊事件,需要div#btnPlane和div#btnOk來分別承載“飛機”和“對勾”。

<div class="btnContainer">  <label id="btnLabel" for="btnInput"></label>  <input type="checkbox" id="btnInput" name="btnInput" />  <div id="btnPlane"></div>  <div id="btnOk"></div></div>

CSS部分代碼如下,使用CSSReset和prefix-free。

/* * 頁面盒子屬性設定,頁面背景顏色設定 * */div{box-sizing: border-box;}body {background: #FF7F50;}/* * 按鈕容器設定 * 大小、水平垂直置中顯示、圓角和溢出設定 * */.btnContainer {width: 100px;height: 100px;margin: auto;position: absolute;left: 0;right: 0;top: 0;bottom: 0;border: 2px solid #fff;border-radius: 50%;overflow: hidden;/* 修正border-radius時,webkit核心的overflow:hidden問題*/-webkit-mask-image: -webkit-radial-gradient(circle, white 100%, black 100%);}/* * 標籤設定 * 大小和容器相同,滑鼠設定,層次設定 * */.btnContainer #btnLabel {display: block;width: 100px;height: 100px;cursor: pointer;position: absolute;z-index: 100;}/* * 複選框設定 * 隱藏 * */.btnContainer input[type="checkbox"] {display: none;}/* * “飛機”設定 * 大小、背景設定,過渡設定 * */.btnContainer #btnPlane {width: 100px;height: 100px;background: url(https://i.cloudup.com/gBzAn-oW_S-2000x2000.png) center center no-repeat;background-size: 50%;transition: all 2s;}/* * “對勾”設定 * 大小、背景設定,位置設定,過渡設定 * */.btnContainer #btnOk {width: 100px;height: 100px;background: url(https://i.cloudup.com/2ZAX3hVsBE-3000x3000.png) center center no-repeat;background-size: 20%;margin: auto;position: absolute;left: 0;right: 0;top: 0;bottom: 0;opacity: 0;transition: all .5s ease 1s;}/* * 響應設定 * 單擊之後的“飛機”和對勾 * */.btnContainer input[type="checkbox"]:checked~ #btnPlane{       transform: translate(100px, -100px);}.btnContainer input[type="checkbox"]:checked~ #btnOk{       opacity: 1;}

這裡需要重點注意一個chrome瀏覽的bug,chrome瀏覽器在設定border-radius時,overflow:hidden在圓角部分會失效,文中進行了修正。Enjoy it.

----------------------------------------------------------

前端開發whqet,關注web前端開發,分享相關資源,歡迎點贊,歡迎拍磚。
---------------------------------------------------------------------------------------------------------

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.