基于slideout.js實(shí)現(xiàn)移動(dòng)端側(cè)邊欄滑動(dòng)特效
HTML5現(xiàn)在本領(lǐng)太大了,PC端已經(jīng)無法滿足它的胃口了,它將強(qiáng)勢(shì)攻入移動(dòng)端,所以移動(dòng)端中各種特效也得基于HTML5實(shí)現(xiàn),看看我們將要介紹的slideout.js,能幫我們實(shí)現(xiàn)怎么樣的側(cè)邊欄滑動(dòng)特效呢
先看下運(yùn)行效果:
一、準(zhǔn)備資料
只需要準(zhǔn)備slideout.js庫即可:
https://github.com/Mango/slideout/blob/master/dist/slideout.js
小圖標(biāo):
二、實(shí)現(xiàn)代碼
HTML代碼:
<!doctype html> <html lang="zh"> <head> <meta charset="UTF-8"> <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <title>適合移動(dòng)手機(jī)的側(cè)邊欄滑動(dòng)代碼 - 站長(zhǎng)素材</title> <link rel="stylesheet" href="css/styles.css"> </head> <body> <nav id="menu" class="menu"> <a href="#" target="_blank"> <header class="menu-header"> <span class="menu-header-title">主題</span> </header> </a> <section class="menu-section"> <h3 class="menu-section-title">腳本代碼</h3> <ul class="menu-section-list"> <li><a href="#" target="_blank">jQuery</a></li> <li><a href="#" target="_blank">CSS3</a></li> <li><a href="#" target="_blank">HTML5</a></li> <li><a href="#" target="_blank">動(dòng)畫效果</a></li> </ul> </section> <section class="menu-section"> <h3 class="menu-section-title">flash動(dòng)畫</h3> <ul class="menu-section-list"> <li><a href="#" target="_blank">節(jié)日動(dòng)畫</a></li> <li><a href="#" target="_blank">flash植物</a></li> <li><a href="#">flash動(dòng)物</a></li> </ul> </section> <section class="menu-section"> <h3 class="menu-section-title">音效下載</h3> <ul class="menu-section-list"> <li><a href="#" target="_blank">鳥叫聲</a></li> <li><a href="#" target="_blank">狗叫聲</a></li> </ul> </section> </nav> <main id="main" class="panel"> <button class="btn-hamburger js-slideout-toggle"> <span class="tooltip">點(diǎn)擊打開</span> </button> </main> <script type="text/javascript" src="js/slideout.min.js"></script> <script type="text/javascript"> var slideout = new Slideout({ 'panel': document.getElementById('main'), 'menu': document.getElementById('menu'), 'padding': 256, 'tolerance': 70 }); document.querySelector('.js-slideout-toggle').addEventListener('click', function() { slideout.toggle(); }); document.querySelector('.menu').addEventListener('click', function(eve) { if (eve.target.nodeName === 'A') { slideout.close(); } }); </script> </body> </html>
結(jié)構(gòu)代碼一項(xiàng)簡(jiǎn)單,主要注意一下slideout的用法,它傳的幾個(gè)參數(shù):
panel:是指主要面板,指整個(gè)內(nèi)容展示區(qū)域
menu:是指被隱藏的左側(cè)菜單欄區(qū)域
padding:指點(diǎn)擊按鈕后,向右滑動(dòng)的距離
CSS代碼:
html, body { width: 100%; height: 100%; font: 100%/1.4em 'Calibre Light', 'Helvetica Neue', Helvetica, Arial, sans-serif; margin: 0 auto; color: #222; -webkit-text-size-adjust: none; -webkit-font-smoothing: antialiased; } pre { margin: 0; font-size: 14px; } body, .panel { background-color: #fff; } .menu { background-color: #1D1F20; background-image: linear-gradient(145deg, #1D1F20, #404348); } a { color: #4B5; text-decoration: none; } .menu a { color: #fff; } .menu a:hover { text-decoration: underline; } .menu-header { border-bottom: 1px solid #2a2d2f; padding: 20px 0 20px 60px; background: url('../images/github.png') no-repeat 15px 15px; background-size: 32px; } .menu-header-title { font-weight: 400; letter-spacing: 0.5px; margin: 0; } .menu-section { margin: 25px 0; } .menu-section-title { text-transform: uppercase; color: #85888d; font-weight: 200; font-size: 13px; letter-spacing: 1px; padding: 0 20px; margin:0; } .menu-section-list { padding:0; margin: 10px 0; list-style:none; } .menu-section-list a { display: block; padding: 10px 20px; } .menu-section-list a:hover { background-color: rgba(255, 255, 255, 0.1); text-decoration: none; } .panel { text-align: center; padding-top: 5px; min-height: 100%; } /** * hamburger */ .btn-hamburger { border: none; position: absolute; top: 12px; left: 12px; outline:none; background: url('../images/menu.png') no-repeat left center; } .tooltip { font-size: 20px; line-height: 19px; display: inline-block; background: #4B5 url('../images/happy.png') no-repeat 135px 15px; color: #fff; padding: 10px 45px 10px 20px; border-radius: 4px; position: relative; left: 50px; } /** * Medium Screens */ @media all and (min-width:40em) { .btn-hamburger { top: 20px; left: 30px; } .panel-header { margin-top: 40px; width: 455px; } .title { font-size: 4.2em; } .subtitle { font-size: 1.8em; } .btn-download { margin-right: 20px; } .btn-fork { margin-left: 20px; } } .menu, .slideout-menu { position: fixed; left: 0; top: 0; bottom: 0; right: 0; z-index: 0; width: 256px; overflow-y: scroll; -webkit-overflow-scrolling: touch; display: none; } .panel, .slideout-panel { position: relative; z-index: 1; } .slideout-open, .slideout-open body { overflow: hidden; } .slideout-open .slideout-menu { display: block; }
上面css代碼可能有些有點(diǎn)多余,但是我們沒必要care這么多細(xì)節(jié)呀,出來效果不就行了么。
以上就是本文的全部?jī)?nèi)容,希望對(duì)大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。
- 博客側(cè)邊欄模塊跟隨滾動(dòng)條滑動(dòng)固定效果的實(shí)現(xiàn)方法(js+jquery等)
- javascript實(shí)現(xiàn)動(dòng)態(tài)側(cè)邊欄代碼
- JavaScript實(shí)現(xiàn)簡(jiǎn)單的隱藏式側(cè)邊欄功能示例
- javascript 實(shí)現(xiàn)動(dòng)態(tài)側(cè)邊欄實(shí)例詳解
- 利用js編寫響應(yīng)式側(cè)邊欄
- JS實(shí)現(xiàn)側(cè)邊欄鼠標(biāo)經(jīng)過彈出框+緩沖效果
- JS運(yùn)動(dòng)框架之分享側(cè)邊欄動(dòng)畫實(shí)例
- JavaScript中實(shí)現(xiàn)無縫滾動(dòng)、分享到側(cè)邊欄實(shí)例代碼
- JS實(shí)現(xiàn)京東商品分類側(cè)邊欄
- js實(shí)現(xiàn)淘寶固定側(cè)邊欄
相關(guān)文章
Handtrack.js庫實(shí)現(xiàn)實(shí)時(shí)監(jiān)測(cè)手部運(yùn)動(dòng)(推薦)
這篇文章主要介紹了實(shí)時(shí)監(jiān)測(cè)手部運(yùn)動(dòng)的 JS 庫,可以實(shí)現(xiàn)很多有趣功能,本文給大家介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或工作具有一定的參考借鑒價(jià)值,需要的朋友可以參考下2021-02-02javascript實(shí)現(xiàn)簡(jiǎn)單倒計(jì)時(shí)效果
這篇文章主要為大家詳細(xì)介紹了javascript實(shí)現(xiàn)倒計(jì)時(shí)效果,文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2021-09-09JS字符串轉(zhuǎn)GBK編碼超精簡(jiǎn)實(shí)現(xiàn)詳解
JS中GBK編碼轉(zhuǎn)字符串是非常簡(jiǎn)單的,但反過來,字符串轉(zhuǎn)GBK編碼卻沒這么簡(jiǎn)單。接下來本文就將帶大家一起康康JS如何實(shí)現(xiàn)字符串轉(zhuǎn)GBK編碼,需要的可以參考一下2022-08-08onbeforeunload與onunload事件異同點(diǎn)總結(jié)
本文對(duì)onbeforeunload與onunload事件的異同點(diǎn)、觸發(fā)于、可以用在哪些元素以及解決刷新頁面時(shí)不調(diào)用onbeforeunload等等,感興趣的朋友可以參考下哈2013-06-06javascript設(shè)計(jì)模式 – 裝飾模式原理與應(yīng)用實(shí)例分析
這篇文章主要介紹了javascript設(shè)計(jì)模式 – 裝飾模式,結(jié)合實(shí)例形式分析了javascript裝飾模式基本概念、原理、應(yīng)用場(chǎng)景及操作注意事項(xiàng),需要的朋友可以參考下2020-04-04