使用CSS3和Checkbox實(shí)現(xiàn)JQuery的一些效果

show()/hide()的實(shí)現(xiàn)
show()/hide()的實(shí)現(xiàn)主要控制元素的display屬性。
html:
- <div id="box">
- <input type="checkbox" id="sh"/>
- <label for="sh">show/hide</label>
- <div id="shbox">
- 點(diǎn)擊上面的show/hide實(shí)現(xiàn)show()/hide()
- </div>
- </div>
css:
- #box{
- position:relative;
- }
- #box *:not(#shbox){
- display:inline-block;
- }
- input{
- position:absolute;
- left:-10000000px;
- }
- :checked~#shbox{
- display:none;
- }
- label{
- width:100px;
- height:30px;
- line-height:30px;
- text-align:center;
- border:1px solid green;
- position:absolute;
- left:0px;
- cursor:pointer;
- border-radius:5px;
- }
- #shbox{
- background:#ccc;
- color:red;
- width:200px;
- height:200px;
- border:1px solid blue;
- box-sizing:border-box;
- padding:50px;
- position:absolute;
- top:50px;
- }
運(yùn)行結(jié)果:https://jsfiddle.net/dwqs/1LykzL2f/1/embedded/result/
fadeIn()/fadeOut()的實(shí)現(xiàn)
fadeIn()/fadeOut()的實(shí)現(xiàn)主要是控制元素的opcity屬性。html依舊采用上面的,修改css如下:
- :checked~#shbox{
- opacity:0;
- }
fadeIn()/fadeOut()可以控制漸顯/漸退的速度,同樣給#shbox添加transition屬性可以模擬這個(gè)效果:
- #shbox{
- transition:opacity 2s;
- }
運(yùn)行效果:https://jsfiddle.net/dwqs/2txfyr1e/embedded/result/
slideUp()/slideDown()的實(shí)現(xiàn)
slideUp()/slideDown()通過(guò)改變?cè)氐母叨葋?lái)實(shí)現(xiàn)上卷和下拉。html依舊采用上面的,css修改如下:
- :checked~#shbox{
- height:0px;
- }
- #shbox{
- background:#ccc;
- overflow-y:hidden;
- color:red;
- width:200px;
- height:200px;
- box-sizing:border-box;
- transition:all 2s;
- position:absolute;
- top:50px;
- }
#shbox添加了 overflow-y:hidden,是為了連文本也實(shí)現(xiàn)隱藏,不然,#shbox里面的文本仍然會(huì)顯示; transition實(shí)現(xiàn)一個(gè)過(guò)渡;同時(shí)去掉了border屬性。
運(yùn)行結(jié)果:https://jsfiddle.net/dwqs/xyu58nu8/3/embedded/result/
相關(guān)文章
jQuery+CSS3實(shí)現(xiàn)自動(dòng)輪播切換焦點(diǎn)圖特效源碼
jQuery+CSS3實(shí)現(xiàn)自動(dòng)輪播切換焦點(diǎn)圖特效源碼是一個(gè)自動(dòng)輪播切換焦點(diǎn)圖代碼,分部加載小圖組合效果。本段代碼適應(yīng)于所有網(wǎng)頁(yè)使用2015-07-08jQuery+CSS3實(shí)現(xiàn)的鼠標(biāo)點(diǎn)擊顯示動(dòng)畫(huà)過(guò)渡效果特效源碼
是一款包含兩種不同切換效果的jQuery特效的代碼。本段代碼適應(yīng)于所有網(wǎng)頁(yè)使用,有興趣的朋友們可以前來(lái)下載使用2015-07-07基于jQuery+CSS3+HTML5實(shí)現(xiàn)的炫酷全屏垂直滾動(dòng)切換幻燈片特效源碼
HTML5全屏垂直滾動(dòng)切換幻燈片是一段基于jQuery+CSS3+HTML5實(shí)現(xiàn)的炫酷全屏垂直滾動(dòng)切換幻燈片特效代碼,本段代碼適應(yīng)于所有網(wǎng)頁(yè)使用,有興趣的朋友們可以前來(lái)下載使用2015-07-06