前端小TIPS:分享下菜单下拉应用,学习下啦。
<!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title>Document</title> <link rel="stylesheet" href="http://cdn.staticfile.org/twitter-bootstrap/3.2.0/css/bootstrap.min.css"> <!-- <link rel="stylesheet" href="http://www.bootcss.com/p/flat-ui/css/flat-ui.css"> --> <style> .container{ padding-top: 10em; text-align: center;} .slide-down{ position: fixed; top: 0; left: 0; width: 100%; height: 100%; visibility: hidden; opacity: 0.9; transition: transform 0.4s ease-in-out, visibility 0s 0.4s; transform: translateY(-100%); background: #2ECC71;} .slide-down.open{ visibility: visible; transition: transform 0.4s ease-in-out; transform: translateY(0);} .slide-down a{ color: #fff; } .close{ position: absolute; right: 20px; top: 20px; font-size: 40px;} .menu-list{ padding: 100px 0 0;} .menu-list li{ line-height: 2em; text-align: center; font-size: 30px} </style> </head> <body> <div class="container"> <a href="#" class="btn btn-lg btn-success btn-menu">Menu</a> </div> <nav class="slide-down palette palette-emerald"> <a href="#" class="close fui-cross">×</a> <ul class="menu-list list-unstyled"> <li><a href="#">about</a></li> <li><a href="#">about</a></li> <li><a href="#">about</a></li> <li><a href="#">about</a></li> <li><a href="#">about</a></li> </ul> </nav> <script> (function(){ var oMenu = document.querySelector('.btn-menu'); var oSlide = document.querySelector('.slide-down'); var oClose = document.querySelector('.close'); var isOpen = false; var toggleMenu = function(o){ isOpen = o || !isOpen; oSlide.classList[isOpen ? 'add' : 'remove']('open'); }; oMenu.addEventListener('click', function(){ toggleMenu(true); }, false); oClose.addEventListener('click', function(){ toggleMenu(false); }, false); })(); </script> </body> </html>
网友评论文明上网理性发言 已有0人参与
发表评论: