jquery - Making a header/menu bar for an off-canvas navigation menu fixed? -
i'm having trouble making element fixed off-canvas navigation design. http://codepen.io/stuffiestephie/pen/wajxxa
(resize viewport it's less 1000px, header isn't visible otherwise.) in desktop styles, nav bar fixed, in mobile header isn't though have !important declaration
$(".toggle-nav").click(function() { // calling function in case want expand upon this. togglenav(); }); function togglenav() { if ($('#drawer').hasclass('show-nav')) { $('#drawer').removeclass('show-nav'); $('#nav-icon').removeclass('open'); } else { $('#drawer').addclass('show-nav'); $('#nav-icon').addclass('open'); } } $('#closebutton').click(function() { $('#drawer').removeclass('show-nav'); $('#nav-icon').removeclass('open'); }); $("nav h3").click(function(){ $("nav ul ul").slideup(); if(!$(this).next().is(":visible")) { $(this).next().slidedown(); } }); $("#downsplasharrow").click(function(event) { event.preventdefault(); if ($('header').is(":visible")) { $('#site-canvas').animate({ scrolltop: $("#page-content").offset().top }, 1000); } else { $('body').animate({ scrolltop: $("#page-content").offset().top }, 1000); } } );
/* import custom fonts */ @import url(http://fonts.googleapis.com/css?family=montserrat:400,700); /* reset default browser styles */ html, body, a, h1, h2, h3, h4, h5, h6, ul, li, span { margin: 0; padding: 0; border: 0; font-size: 100%; font: inherit; vertical-align: baseline; text-decoration: none; list-style-type: none; color: inherit; } html, body { height: 100%; /*overflow: hidden;*/ } /* navagation */ nav { width: 100%; font-family: montserrat, 'montserrat-regular', 'montserrat-regular-eot', sans-serif; font-weight: 700; background: #333; height: 55px; text-align: center; position: fixed; z-index: 10; font-size: .8em; text-transform: uppercase; } /* nav img { height: 100%; vertical-align:middle; margin-right: 50px; display: inline; } */ header, #closebutton { display: none; } nav ul li { /*width: 11%; min-width: 140px; */ color: #ddd; float: left; display: inline-block; } nav li a{ display: inline-block; line-height: 55px; padding: 0 5px 0 20px; } nav li ul{ display: none; width: 200px; position: absolute; font-size: .8em; } nav li:hover { color: #3c6ddf; background-color: #8db3ff; } nav li li { line-height: 1em; padding: 20px 0; width: 200px; background: #333333; } nav li li a:hover { background-color: #8db3ff; } nav li span { font-weight:900; padding: 0 0px 0 .5em; cursor:pointer; } #site-canvas { width: 100%; height: 100%; /*overflow-y: scroll;*/ } /* splash page */ .splash { background: url('http://netdna.webdesignerdepot.com/uploads7/how-to-create-a-scrollable-splash-screen-with-css3-and-jquery/img/splash-bg.jpg') center center; background-size: cover; min-height: 100%; width: 100%; background-size: cover; min-height: 100%; width: 100%; text-align: center; position:relative; /* position:absolute; top: 0; left: 0; z-index: 0; */ } a.splash-arrow { color: white; font-size: 1.2em; position: absolute; bottom: 55px; left: 50%; margin-left: -25px; padding: 10px; width: 50px; height: 50px; font-weight: bold; -webkit-transition: 0.1s ease; -moz-transition: 0.1s ease; -o-transition: 0.1s ease; transition: 0.1s ease; -webkit-animation-delay: 1.5s; -moz-animation-delay: 1.5s; animation-delay: 1.5s; border: 3px solid white; -webkit-border-radius: 50%; -moz-border-radius: 50%; border-radius: 50%; } .splash-arrow img { margin-top: 40%; } a.splash-arrow:hover { text-decoration: none; bottom: 50px; } @media screen , (max-width: 949px) { #closebutton { display: block; line-height: 55px; border-bottom: none; } html, body { height: 100%; overflow: hidden; } /* mobile slideout */ #drawer { min-width: 200px; position: absolute; top: 0; left: -300px; height: 100%; width: 300px; background: #2f2f2f; overflow-x: hidden; overflow-y: auto; -webkit-overflow-scrolling: touch; -webkit-transform: translatex(0); transform: translatex(0); -webkit-transition: .3s ease all; transition: .3s ease all; } #site-canvas { width: 100%; height: 100%; overflow-x: hidden; overflow-y: scroll; -webkit-transform: translatex(0); transform: translatex(0); -webkit-transition: .3s ease all; transition: .3s ease all; position: relative; } header { width: 100%; display: block; top: 0px; left: 0px; right: 0px; height: 55px; position: fixed !important; background: #333; z-index: 1; -webkit-transform: translatex(0); transform: translatex(0); -webkit-transition: .3s ease all; transition: .3s ease all; } /* show-nav styles */ #drawer.show-nav, #drawer.show-nav + #site-canvas { -webkit-transform: translatex(300px); transform: translatex(300px); } #drawer.show-nav + #site-canvas { background: rgba(255, 255, 255, .8); height: 100%; } /*general navagation*/ nav { font-family: montserrat, 'montserrat-regular', 'montserrat-regular-eot', sans-serif; font-weight: 700; background: #333; height: 55px; text-align:center; font-size: .8em; text-transform: uppercase; position: absolute; z-index: 11; } nav h3 { font-size: 2em; background: #283744; border-bottom: 1px solid #ddd;; cursor: pointer; } #closebutton { background: #333; } nav ul ul { display: none; } nav ul li { /*width: 11%; min-width: 140px; */ color: #ddd; float: none; display: block; } nav li ul{ width: 100%; position: relative; } nav li ul li { width: 100% } /* icon 1 */ #nav-icon { width: 60px; height: 45px; position: relative; margin-left: 10px; -webkit-transform: rotate(0deg); -moz-transform: rotate(0deg); -o-transform: rotate(0deg); transform: rotate(0deg); -webkit-transition: .5s ease-in-out; -moz-transition: .5s ease-in-out; -o-transition: .5s ease-in-out; transition: .5s ease-in-out; cursor: pointer; display: inline-block; } #nav-icon span { display: block; position: absolute; height: 9px; width: 100%; background: rgb(145, 16, 20); border-radius: 9px; opacity: 1; left: 0; -webkit-transform: rotate(0deg); -moz-transform: rotate(0deg); -o-transform: rotate(0deg); transform: rotate(0deg); -webkit-transition: .25s ease-in-out; -moz-transition: .25s ease-in-out; -o-transition: .25s ease-in-out; transition: .25s ease-in-out; } /* menu icon*/ #nav-icon span:nth-child(1) { top: 0px; -webkit-transform-origin: left center; -moz-transform-origin: left center; -o-transform-origin: left center; transform-origin: left center; } #nav-icon span:nth-child(2) { top: 18px; -webkit-transform-origin: left center; -moz-transform-origin: left center; -o-transform-origin: left center; transform-origin: left center; } #nav-icon span:nth-child(3) { top: 36px; -webkit-transform-origin: left center; -moz-transform-origin: left center; -o-transform-origin: left center; transform-origin: left center; } #nav-icon.open span:nth-child(1) { -webkit-transform: translate(8px,-4px) rotate(45deg); -moz-transform: translate(8px,-4px) rotate(45deg); -o-transform: translate(8px,-4px) rotate(45deg); transform: translate(8px,-4px) rotate(45deg); } #nav-icon.open span:nth-child(2) { width: 0%; opacity: 0; } #nav-icon.open span:nth-child(3) { -webkit-transform: translate(8px,2px) rotate(-45deg); -moz-transform: translate(8px,2px) rotate(-45deg); -o-transform: translate(8px,2px) rotate(-45deg); transform: translate(8px,2px) rotate(-45deg); //top: 39px; //left: 8px; } }
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.3/jquery.min.js"></script> <html> <head> <!-- meta --> <meta charset="utf-8"> <title>off canvas menus demo</title> <meta http-equiv="x-ua-compatible" content="ie=edge,chrome=1"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <!-- favicon --> <!-- styles --> <link rel="stylesheet" href="https://netdna.bootstrapcdn.com/font-awesome/4.0.3/css/font-awesome.css"> <!--[if lt ie 9]><script src="//html5shiv.googlecode.com/svn/trunk/html5.js"></script><![endif]--> </head> <body> <nav id="drawer"> <ul> <h3 id="closebutton"><li><i class="fa fa-times-circle-o"></i> close <i class="fa fa-times-circle-o"></i></li></h3> <li> <h3><a href="#" title="our event home page">home</a></h3></li> <li> <h3><a href="#" id="events">events <span>+</span></a></h3> <ul id="eventsmenu" class="submenu"> <li><a href="#">some contest</a></li> <li><a href="#">another contest</a></li> <li><a href="#">misc. events</a></li> <li><a href="#">dance</a></li> <li><a href="#">concert</a></li> <li><a href="#">an event long title</a></li> </ul> </li> <li class="csshover topmain"> <h3><a href="#" id="rooms">rooms <span>+</span></a></h3> <ul id ="roomsmenu" class="submenu"> <li><a href="#">art gallery</a></li> <li><a href="#">market room</a></li> <li><a href="#">some other room</a></li> <li><a href="#">film screening</a></li> <li><a href="#">gaming</a></li> <li><a href="#">our shop</a></li> </ul> </li> <li class="topmain"> <h3> <a href="#">special guests</a> </h3> </li> <li class="csshover topmain"> <h3><a href="#" id="info">information <span>+</span></a></h3> <ul id="infomenu" class="submenu"> <li><a href="#">parents info</a></li> <li><a href="#">our policies</a></li> <li><a href="#">maps / location</a></li> <li><a href="#">need hotel?</a></li> </ul> </li> <li class="csshover topmain"> <h3><a href="#" id="story">history <span>+</span></a></h3> <ul id="storymenu" class="submenu"> <li><a href="#">previous festivals</a></li> <li><a href="#">meet staff</a></li> <li><a href="#">artwork</a></li> </ul> </li> <li class="csshover topmain"> <h3><a href="#" id="contact">contact <span>+</span></a></h3> <ul id="contactmenu" class="submenu"> <li><a href="#">contact staff</a></li> <li><a href="#">volunteer</a></li> <li><a href="#">submit idea</a></li> <li><a href="#">advertise our event</a></li> </ul> </li> <li class="topmain"><h3><a href="#">registration</a></h3></li> </ul> </nav> <!-- end menu --> <div id="site-canvas"> <header> <a href="#" class="toggle-nav" ><div id="nav-icon"> <span></span> <span></span> <span></span> </div></a> <img src="http://www.wpclipart.com/blanks/buttons/glossy_buttons/glossy_button_blank_red_rectangle_t.png" height="50"></header> <div class="splash"> <a href="#" id="downsplasharrow" class="splash-arrow"><img src="http://netdna.webdesignerdepot.com/uploads7/how-to-create-a-scrollable-splash-screen-with-css3-and-jquery/img/down-arrow.png"></a> </div> <div id="page-content"> <p>text begins here lorem ipsum dolor sit amet, consectetur adipiscing elit. nullam tincidunt congue sapien, eu fermentum elit sollicitudin sit amet. nulla quam est, tincidunt sed risus id, interdum elementum velit. curabitur varius justo, eget pharetra urna. maecenas @ tincidunt purus. quisque dignissim sagittis nunc, quis commodo justo efficitur a. nam congue felis vel est mollis, vitae tristique libero viverra. nulla cursus, sapien sed mattis maximus, ligula tellus dapibus diam, in vulputate erat lorem ut neque. suspendisse scelerisque eros enim, id lobortis lacus maximus eu. aliquam augue ipsum, mattis et suscipit vel, facilisis vitae ipsum. praesent semper magna ligula, id molestie eros tempus vitae. nullam eu quam quis nibh sodales fringilla. vivamus molestie fermentum urna nec ultricies. mauris ut convallis ligula, sit amet laoreet nulla. mauris pellentesque elit nec risus laoreet, elementum faucibus erat vulputate. curabitur consectetur, lacus aliquam iaculis finibus, metus metus porta metus, vitae bibendum mi ante porttitor lectus. aliquam dui felis, auctor ut aliquet pellentesque, dignissim in nisl. phasellus finibus finibus ante id vulputate. suspendisse ipsum blandit tortor rhoncus tincidunt eu ut tortor. aenean convallis quam id tortor tincidunt, eu rutrum lectus ultricies. aenean aliquet in velit luctus porta. phasellus nec urna volutpat, posuere purus at, euismod nulla. maecenas sed accumsan libero. duis efficitur porttitor elit, sed commodo leo mattis eu. aenean sit amet dui euismod, finibus lectus non, fermentum quam. morbi vel rutrum quam, non iaculis ipsum. vestibulum rutrum justo @ consequat euismod. sed feugiat nec velit ac laoreet. etiam elit tellus, posuere in semper id, porta ut purus. vestibulum sagittis id risus ut finibus. morbi sagittis mattis tempor. maecenas bibendum egestas rhoncus. nulla facilisi. integer eleifend, nibh in molestie blandit, tortor turpis finibus risus, ut pellentesque odio magna nisl. integer porttitor congue semper. cras vulputate, tortor non iaculis elementum, massa velit convallis ipsum, varius nisl nunc vel nisi. nam accumsan eros eget augue varius, ac interdum tellus pretium. morbi malesuada lectus quis elit blandit volutpat. duis odio erat, fermentum id nibh facilisis, fringilla congue urna. sed scelerisque nunc ac ante varius, eget vulputate urna dictum. proin vel pulvinar velit, sed faucibus orci. integer varius nisi eget egestas convallis. in eget elit pharetra, posuere nisi a, convallis nulla. etiam volutpat magna sit amet pharetra volutpat. aliquam sed orci viverra, mattis nibh sit amet, mollis ante. morbi elementum diam neque, quis ultrices quam dignissim non. phasellus tincidunt tincidunt nisi. vestibulum commodo diam lorem, id vulputate felis lacinia nec. </p> <p>lorem ipsum dolor sit amet, consectetur adipiscing elit. nullam tincidunt congue sapien, eu fermentum elit sollicitudin sit amet. nulla quam est, tincidunt sed risus id, interdum elementum velit. curabitur varius justo, eget pharetra urna. maecenas @ tincidunt purus. quisque dignissim sagittis nunc, quis commodo justo efficitur a. nam congue felis vel est mollis, vitae tristique libero viverra. nulla cursus, sapien sed mattis maximus, ligula tellus dapibus diam, in vulputate erat lorem ut neque. suspendisse scelerisque eros enim, id lobortis lacus maximus eu. aliquam augue ipsum, mattis et suscipit vel, facilisis vitae ipsum. praesent semper magna ligula, id molestie eros tempus vitae. nullam eu quam quis nibh sodales fringilla. vivamus molestie fermentum urna nec ultricies. mauris ut convallis ligula, sit amet laoreet nulla. mauris pellentesque elit nec risus laoreet, elementum faucibus erat vulputate. curabitur consectetur, lacus aliquam iaculis finibus, metus metus porta metus, vitae bibendum mi ante porttitor lectus. aliquam dui felis, auctor ut aliquet pellentesque, dignissim in nisl. phasellus finibus finibus ante id vulputate. suspendisse ipsum blandit tortor rhoncus tincidunt eu ut tortor. aenean convallis quam id tortor tincidunt, eu rutrum lectus ultricies. aenean aliquet in velit luctus porta. phasellus nec urna volutpat, posuere purus at, euismod nulla. maecenas sed accumsan libero. duis efficitur porttitor elit, sed commodo leo mattis eu. aenean sit amet dui euismod, finibus lectus non, fermentum quam. morbi vel rutrum quam, non iaculis ipsum. vestibulum rutrum justo @ consequat euismod. sed feugiat nec velit ac laoreet. etiam elit tellus, posuere in semper id, porta ut purus. vestibulum sagittis id risus ut finibus. morbi sagittis mattis tempor. maecenas bibendum egestas rhoncus. nulla facilisi. integer eleifend, nibh in molestie blandit, tortor turpis finibus risus, ut pellentesque odio magna nisl. integer porttitor congue semper. cras vulputate, tortor non iaculis elementum, massa velit convallis ipsum, varius nisl nunc vel nisi. nam accumsan eros eget augue varius, ac interdum tellus pretium. morbi malesuada lectus quis elit blandit volutpat. duis odio erat, fermentum id nibh facilisis, fringilla congue urna. sed scelerisque nunc ac ante varius, eget vulputate urna dictum. proin vel pulvinar velit, sed faucibus orci. integer varius nisi eget egestas convallis. in eget elit pharetra, posuere nisi a, convallis nulla. etiam volutpat magna sit amet pharetra volutpat. aliquam sed orci viverra, mattis nibh sit amet, mollis ante. morbi elementum diam neque, quis ultrices quam dignissim non. phasellus tincidunt tincidunt nisi. vestibulum commodo diam lorem, id vulputate felis lacinia nec. </p> <p>lorem ipsum dolor sit amet, consectetur adipiscing elit. nullam tincidunt congue sapien, eu fermentum elit sollicitudin sit amet. nulla quam est, tincidunt sed risus id, interdum elementum velit. curabitur varius justo, eget pharetra urna. maecenas @ tincidunt purus. quisque dignissim sagittis nunc, quis commodo justo efficitur a. nam congue felis vel est mollis, vitae tristique libero viverra. nulla cursus, sapien sed mattis maximus, ligula tellus dapibus diam, in vulputate erat lorem ut neque. suspendisse scelerisque eros enim, id lobortis lacus maximus eu. aliquam augue ipsum, mattis et suscipit vel, facilisis vitae ipsum. praesent semper magna ligula, id molestie eros tempus vitae. nullam eu quam quis nibh sodales fringilla. vivamus molestie fermentum urna nec ultricies. mauris ut convallis ligula, sit amet laoreet nulla. mauris pellentesque elit nec risus laoreet, elementum faucibus erat vulputate. curabitur consectetur, lacus aliquam iaculis finibus, metus metus porta metus, vitae bibendum mi ante porttitor lectus. aliquam dui felis, auctor ut aliquet pellentesque, dignissim in nisl. phasellus finibus finibus ante id vulputate. suspendisse ipsum blandit tortor rhoncus tincidunt eu ut tortor. aenean convallis quam id tortor tincidunt, eu rutrum lectus ultricies. aenean aliquet in velit luctus porta. phasellus nec urna volutpat, posuere purus at, euismod nulla. maecenas sed accumsan libero. duis efficitur porttitor elit, sed commodo leo mattis eu. aenean sit amet dui euismod, finibus lectus non, fermentum quam. morbi vel rutrum quam, non iaculis ipsum. vestibulum rutrum justo @ consequat euismod. sed feugiat nec velit ac laoreet. etiam elit tellus, posuere in semper id, porta ut purus. vestibulum sagittis id risus ut finibus. morbi sagittis mattis tempor. maecenas bibendum egestas rhoncus. nulla facilisi. integer eleifend, nibh in molestie blandit, tortor turpis finibus risus, ut pellentesque odio magna nisl. integer porttitor congue semper. cras vulputate, tortor non iaculis elementum, massa velit convallis ipsum, varius nisl nunc vel nisi. nam accumsan eros eget augue varius, ac interdum tellus pretium. morbi malesuada lectus quis elit blandit volutpat. duis odio erat, fermentum id nibh facilisis, fringilla congue urna. sed scelerisque nunc ac ante varius, eget vulputate urna dictum. proin vel pulvinar velit, sed faucibus orci. integer varius nisi eget egestas convallis. in eget elit pharetra, posuere nisi a, convallis nulla. etiam volutpat magna sit amet pharetra volutpat. aliquam sed orci viverra, mattis nibh sit amet, mollis ante. morbi elementum diam neque, quis ultrices quam dignissim non. phasellus tincidunt tincidunt nisi. vestibulum commodo diam lorem, id vulputate felis lacinia nec. </p>. </div> <!-- #page-content --> </div><!-- #site-canvas --> </body> </html>
this whole thing kinda convoluted fact header needs slide on rest of canvas when off-canvas menu drawer open.
any ideas?
edit: well, i've discovered rather troubling, jquery scroll-down function (desktop version) works in chrome not in firefox , ie! , in ie header fixed, not in chrome , firefox. ಠ_ಠ
try this:
move <header>
in html outside of #site-canvas
. html structure this:
<body> <nav> <header> <#site-nav>
then add css
nav.show-nav ~ header{ transform: translatex(300px); }
next change css selector:
#drawer.show-nav, #drawer.show-nav + #site-canvas
to this:
#drawer.show-nav, #site-canvas.slide
now toggle new slide
class here:
$(".toggle-nav").click(function() { // calling function in case want expand upon this. $('#site-canvas').toggleclass('slide'); togglenav(); });
i add padding-top:55px;
#site-canvas
give room fixed header.
see update codepen.
Comments
Post a Comment