Why are the CSS transforms not displayed? - javascript
I'm trying to make a navigation panel slide in on the click of a nav button in the main menu. Needless to say, it's not working. I've made this work before, so I'm not sure what's going on. Help?
HTML
<!-- Header -->
<div class="header">
<i id="nav-button" class="fa fa-navicon"></i>
<header class="logo">
<img src="../Assets/images/logo.png" alt="">
</header>
<i class="account-control fa fa-user"></i>
</div>
<div class="wrapper">
<div id="content">
</div>
<!-- Collapsible Menu -->
<div id="sidebar">
<div class="nav-items">
<nav class="mainmenu">
<ul>
<li>Billing</li>
<li>Support</li>
<li>Servers</li>
<li>Settings</li>
<li>Reports</li>
</ul>
</nav>
</div>
<!-- Copyright -->
<footer>
<form action="" class="search">
<input type="search" name="search" placeholder="Search">
</form>
<p class="copyright">asdf</p>
</footer>
</div>
</div>
Relevant CSS
/* Core */
*, *:before, *:after {
-webkit-box-sizing: border-box;
-moz-box-sizing: border-box;
box-sizing: border-box;
}
body {
display: block;
font-family: "Open Sans", sans-serif;
font-size: 12px;
font-weight: 400;
line-height: 1.42857;
color: black;
background-color: white;
}
.wrapper {
position: relative;
width: 100%;
height: 100%;
top: 100px;
z-index: 0;
overflow: hidden;
}
#content {
position: relative;
left: 0;
z-index: 5;
height: 100%;
overflow: auto;
-webkit-transition: -webkit-transform 0.5s;
-moz-transition: -moz-transform 0.5s;
transition: transform 0.5s;
}
.sidebar-open #content {
-webkit-transform: translate(200px, 0);
-moz-transform: translate(200px, 0);
transform: translate(200px, 0);
}
/* Header */
.header {
background-color: #222222;
width: 100%;
height: 100px;
position: absolute;
top: 0;
z-index: 1;
}
#nav-button {
font-size: 24px;
color: white;
position: absolute;
left: 40px;
top: 50%;
-webkit-transform: translateY(-50%);
-moz-transform: translateY(-50%);
transform: translateY(-50%);
}
#nav-button.open {
-webkit-transform: rotate(90deg);
-moz-transform: rotate(90deg);
transform: rotate(90deg);
}
.logo {
position: absolute;
top: 50%;
left: 50%;
-webkit-transform: translate(-50%, -50%);
-moz-transform: translate(-50%, -50%);
transform: translate(-50%, -50%);
}
.account-control {
font-size: 24px;
color: white;
position: absolute;
right: 40px;
top: 50%;
-webkit-transform: translateY(-50%);
-moz-transform: translateY(-50%);
transform: translateY(-50%);
}
/* Navigation */
#sidebar {
position: absolute;
top: 100px;
left: 0;
visibility: hidden;
width: 200px;
height: 100%;
background: #222222;
opacity: 1;
z-index: 1;
-webkit-transform: all 0.5s;
-moz-transform: all 0.5s;
transform: all 0.5s;
-webkit-transform: translate3d(0, -100%, 0);
-moz-transform: translate3d(0, -100%, 0);
transform: translate3d(0, -100%, 0);
}
.sidebar-open #sidebar {
visibility: visible;
-webkit-transition-timing-function: ease-in-out;
-moz-transition-timing-function: ease-in-out;
transition-timing-function: ease-in-out;
-webkit-transition-property: transform;
-moz-transition-property: transform;
transition-property: transform;
-webkit-transform: translate3d(0, 0, 0);
-moz-transform: translate3d(0, 0, 0);
transform: translate3d(0, 0, 0);
-webkit-transition-speed: 0.2s;
-moz-transition-speed: 0.2s;
transition-speed: 0.2s;
}
#sidebar:after {
position: absolute;
top: 0;
right: 0;
width: 100%;
height: 100%;
content: '';
opacity: 1;
-webkit-transition: opacity 0.5s;
-moz-transition: opacity 0.5s;
transition: opacity 0.5s;
}
.sidebar-open #sidebar:after {
width: 0;
height: 0;
opacity: 0;
-webkit-transition: opacity 0.5s, width 0.1s 0.5s, height 0.1s 0.5s;
-moz-transition: opacity 0.5s, width 0.1s 0.5s, height 0.1s 0.5s;
transition: opacity 0.5s, width 0.1s 0.5s, height 0.1s 0.5s;
}
.nav-items {
max-height: 100%;
position: relative;
overflow: auto;
bottom: 60px;
}
.mainmenu ul {
margin: 0;
}
.mainmenu ul li a {
padding: 0 40px;
width: 100%;
line-height: 60px;
display: inline-block;
color: #202020;
text-decoration: none;
}
.mainmenu ul li a :hover, .mainmenu ul li a .active {
background: #e1e1e1;
}
JavaScript
jQuery(document).ready(function($) {
/* Sidebar */
$('#nav-button, #content').click(function() {
$('#nav-button').toggleClass('open');
$('body').toggleClass('sidebar-open');
return false;
});
});(jQuery);
Yes, I am using FontAwesome. :)
Your biggest issue that solves your original question is due to overflow: hidden; on .wrapper.
Here it is removed: DEMO. But that opens up a whole new world of problems. I advise you to go back and refactor your code.
Have you tried to empty your cache?
Ctrl-Shift-Del so your browser will reload your css.
Note: If this happens to your users, try changing the link to your css in your header like this:
<link rel="stylesheet" href="css/main.css?v=2">
Related
How can I disable scrolling when my hamburger menu is open?
I am working on a website with a hamburger menu that fills the entire page when clicked. The only problem is the page behind still scrolls when the nav is open, and I can't figure out how to disable scrolling while the menu is open. I have tried changing overflow-y: hidden, but it doesn't seem to work. Here is the HTML for the menu: <div id="menu"> <div class="logotext"> ONWORD </div> <input type="checkbox" id="myInput"> <label for="myInput"> <span class="bar top"></span> <span class="bar middle"></span> <span class="bar bottom"></span> </label> <aside> <div class="aside-section aside-left"> <div class="aside-content"> <p> Languages of the land</p> </div> </div> <div class="aside-section aside-right"> <ul class="aside-list"> <li>Start Learning</li> <li>Language Map</li> <li>History</li> <li>Stories</li> <li>Contact</li> </ul> </div> </aside> </div> Here is the CSS: .logotext a { font-family: "Raleway", sans-serif; font-size: 20px; text-transform: uppercase; font-weight: 600; letter-spacing: 2px; left: 1%; z-index: 99999; color: white; position: absolute; padding-left: 19px; padding-right: 19px; padding-top: 22px; transition: 0.5s; } .logotext a:hover { -webkit-transform: scale(0.9); transition-delay: 200ms; transition-duration: 0.5s; } .aside-section { top: 0; bottom: 0; position: absolute; z-index: 99998; overflow: hidden; } .aside-left { display: none; width: 40%; left: 0; background-color: white; background-image: url(../img/menu1.jpeg); background-position: center; background-size: cover; -webkit-transform: translateY(-100%); -moz-transform: translateY(-100%); -ms-transform: translateY(-100%); -o-transform: translateY(-100%); transform: translateY(-100%); transition: transform 0.4s ease-in-out; z-index: 99998; position: fixed; overflow-y: hidden; } .aside-right { width: 100%; right: 0; background-color: #000000; -webkit-transform: translateX(100%); -moz-transform: translateX(100%); -ms-transform: translateX(100%); -o-transform: translateX(100%); transform: translateX(100%); transition: transform 0.4s ease-in-out; z-index: 99998; position: fixed; overflow-y: hidden; } .aside-list { list-style: none; padding: 0; margin: 0; margin-top: 160px; text-align: left; padding-left: 50px; z-index: 99998; } .aside-content { margin-top: 150px; padding: 0 40px; position: relative; color: #000000; text-align: center; z-index: 99998; } .aside-list li { margin-bottom: 20px; z-index: 99998; padding-bottom: 7px; } .aside-anchor::after { content: ""; position: absolute; bottom: 0; background-color: #000000; left: 0; right: 0; height: 2px; border-radius: 3px; } .aside-anchor::before { border-radius: 3px; content: ""; position: absolute; bottom: 0; background-color: #f5eded; left: 0; height: 1px; z-index: 1; width: 50%; -webkit-transition: transform 0.2s ease-in-out; -o-transition: transform 0.2s ease-in-out; transition: transform 0.2s ease-in-out; } .aside-anchor:hover:before { -webkit-transform: translateX(50%); -moz-transform: translateX(50%); -ms-transform: translateX(50%); -o-transform: translateX(50%); transform: translateX(50%); background-color: #dd8800; } .aside-anchor { padding-bottom: 5px; color: #fff; text-decoration: none; font-size: 14px; position: relative; font-weight: 400; text-transform: uppercase; letter-spacing: 2px; font-weight: 600; } input[type="checkbox"] { display: none; } input[type="checkbox"]:checked ~ aside .aside-left { transform: translateY(0%); } input[type="checkbox"]:checked ~ aside .aside-right { transform: translateX(0%); } input[type="checkbox"]:checked ~ label .bar { background-color: #fff; } input[type="checkbox"]:checked ~ label .top { -webkit-transform: translateY(0px) rotateZ(45deg); -moz-transform: translateY(0px) rotateZ(45deg); -ms-transform: translateY(0px) rotateZ(45deg); -o-transform: translateY(0px) rotateZ(45deg); transform: translateY(0px) rotateZ(45deg); } input[type="checkbox"]:checked ~ label .bottom { -webkit-transform: translateY(-15px) rotateZ(-45deg); -moz-transform: translateY(-15px) rotateZ(-45deg); -ms-transform: translateY(-15px) rotateZ(-45deg); -o-transform: translateY(-15px) rotateZ(-45deg); transform: translateY(-15px) rotateZ(-45deg); } input[type="checkbox"]:checked ~ label .middle { width: 0; } .middle { margin: 0 auto; } label { top: 10px; display: inline-block; padding: 7px 10px; background-color: transparent; cursor: pointer; margin: 10px; position: absolute; z-index: 99999; text-align: right; right: 1%; transition: 0.5s; } label:hover { -webkit-transform: scale(0.9); transition-delay: 200ms; transition-duration: 0.5s; } .bar { display: block; background-color: #ffffff; width: 30px; height: 3px; border-radius: 5px; margin: 5px auto; transition: background-color 0.4s ease-in, transform 0.4s ease-in, width 0.4s ease-in; z-index: 99999; } .aside-section h1 { margin: 0; position: relative; top: 50%; left: 0; right: 0; transform: translateY(-50%); text-align: center; font-size: 35px; font-family: 'BritishShorthair'; } .aside-section p { font-size: 90px; text-align: center; line-height: 130px; font-family: 'BritishShorthair'; margin-top: 0px; color: white; } #media (min-width: 992px) { h1 { font-size: 40px; } .aside-left { display: block; } .aside-right { width: 60%; } }
When you said you set overflow-y: hidden. Did you do this on the body?
How to get text to animate to look as if it is going under another layer
For a comparable example, view this site. If you look on the left side, you will see rotated text that loops through different lines of text. This is what I am trying to accomplish. The text in this example starts by the white line and then once it starts moving up, it looks as if it goes under a layer to make it seem like it is going out of place. How could I modify my code to handle this? Right now the white line and the text do not appear in line and I cannot figure out how I can make it look like the text is moving under another layer. var arr = $('.textContainer > span'); var arrLen = arr.length; var i = 0; var next_i = 1; var loop = function() { arr.removeClass('curr'); arr.removeClass('next'); $('span[data-index = ' + i + ']').addClass('curr'); $('span[data-index = ' + next_i + ']').addClass('next'); i = (i + 1) % arrLen; next_i = (next_i + 1) % arrLen; }; loop(); setInterval(loop, 3000); #container { background: blue; width: 100%; height: 100vh; } .digitalAgency { height: 20px; position: fixed; top: 50%; left: -45%; width: 100%; text-transform: uppercase; font-weight: 700; font-size: 14px; letter-spacing: 1px; -webkit-transition: opacity .5s; -o-transition: opacity .5s; transition: opacity .5s; -webkit-transition: opacity .5s; -o-transition: opacity .5s; transition: opacity .5s; } .digitalAgency .textContainer::before { content: ""; position: absolute; width: 40px; height: 1px; background: #fff; display: inline-block; top: 50%; margin-right: 20px; left: 33%; } .digitalAgency .textContainer { position: relative; width: 650px; height: 100%; left: 50%; -webkit-transform: translateX(-50%) rotate(-90deg); -ms-transform: translateX(-50%) rotate(-90deg); transform: translateX(-50%) rotate(-90deg); display: inline-block; overflow: hidden; } .digitalAgency, .agencyText { -webkit-animation-duration: .45s; animation-duration: .45s; -webkit-animation-fill-mode: forwards; animation-fill-mode: forwards; -webkit-animation-timing-function: ease-in-out; animation-timing-function: ease-in-out; } .agencyText { font-family: 'Raleway', sans-serif; font-size: 1.1rem; color: #FFF; } .digitalAgency .textContainer .agencyText { padding-left: 60px; position: absolute; visibility: hidden; width: 100%; height: 100%; left: 33%; } .digitalAgency .textContainer .agencyText.curr { visibility: visible; } .digitalAgency .agencyText.curr { visibility: visible; -webkit-animation-name: dgAgnCurr; animation-name: dgAgnCurr } .digitalAgency .agencyText.next { visibility: hidden; -webkit-animation-name: dgAgnNext; animation-name: dgAgnNext } #-webkit-keyframes dgAgnCurr { from { -webkit-transform: translateY(0); transform: translateY(0) } to { -webkit-transform: translateY(-100%); transform: translateY(-100%) } } #keyframes dgAgnCurr { from { -webkit-transform: translateY(0); transform: translateY(0) } to { -webkit-transform: translateY(-100%); transform: translateY(-100%) } } #-webkit-keyframes dgAgnNext { from { -webkit-transform: translateY(100%); transform: translateY(100%) } to { -webkit-transform: translateY(0); transform: translateY(0) } } #keyframes dgAgnNext { from { -webkit-transform: translateY(100%); transform: translateY(100%) } to { -webkit-transform: translateY(0); transform: translateY(0) } } <script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script> <div id="container"> <div class="digitalAgency"> <span class="textContainer"> <span data-index="0" class="agencyText">Text for A</span> <span data-index="1" class="agencyText">Text for B</span> <span data-index="2" class="agencyText">Text for C</span> <span data-index="3" class="agencyText">Text for D</span> </span> </div> </div>
Get rid of the CSS animations and use a simple transition. No need to overcomplicate things. You're simply going from translate -100% to 0% to 100% so you don't really need animation keyframes. var arr = $('.textContainer > span'); var arrLen = arr.length; var i = 0; var next_i = 1; var loop = function() { arr.removeClass('curr'); arr.removeClass('next'); $('span[data-index = ' + i + ']').addClass('curr'); $('span[data-index = ' + next_i + ']').addClass('next'); i = (i + 1) % arrLen; next_i = (next_i + 1) % arrLen; }; loop(); setInterval(loop, 3000); #container { background: blue; width: 100%; height: 100vh; } .digitalAgency { height: 20px; position: fixed; top: 50%; left: -45%; width: 100%; text-transform: uppercase; font-weight: 700; font-size: 14px; letter-spacing: 1px; -webkit-transition: opacity .5s; -o-transition: opacity .5s; transition: opacity .5s; -webkit-transition: opacity .5s; -o-transition: opacity .5s; transition: opacity .5s; } .digitalAgency .textContainer::before { content: ""; position: absolute; width: 40px; height: 1px; background: #fff; display: inline-block; top: 50%; margin-right: 20px; left: 33%; } .digitalAgency .textContainer { position: relative; width: 650px; height: 100%; left: 50%; -webkit-transform: translateX(-50%) rotate(-90deg); -ms-transform: translateX(-50%) rotate(-90deg); transform: translateX(-50%) rotate(-90deg); display: inline-block; overflow: hidden; } .digitalAgency, .agencyText { transition:.45s ease-in-out; /* added this */ } .agencyText { font-family: 'Raleway', sans-serif; font-size: 1.1rem; color: #FFF; } .digitalAgency .textContainer .agencyText { padding-left: 60px; position: absolute; visibility: hidden; width: 100%; height: 100%; left: 33%; transform: translateY(-100%); /* added this */ } .digitalAgency .agencyText.curr { visibility: visible; transform: translateY(0%); /* added this */ } .digitalAgency .agencyText.next { visibility: hidden; transform: translateY(100%); /* added this */ } <script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script> <div id="container"> <div class="digitalAgency"> <span class="textContainer"> <span data-index="0" class="agencyText">Text for A</span> <span data-index="1" class="agencyText">Text for B</span> <span data-index="2" class="agencyText">Text for C</span> <span data-index="3" class="agencyText">Text for D</span> </span> </div> </div>
How to change animation position in Off-Canvas Menu Effects
I'm working with OffCanvasMenuEffects and i'm using wave menu effect. You can see this menu in following: article,aside,details,figcaption,figure,footer,header,hgroup,main,nav,section,summary{display:block;}audio,canvas,video{display:inline-block;}audio:not([controls]){display:none;height:0;}[hidden]{display:none;}html{font-family:sans-serif;-ms-text-size-adjust:100%;-webkit-text-size-adjust:100%;}body{margin:0;}a:focus{outline:thin dotted;}a:active,a:hover{outline:0;}h1{font-size:2em;margin:0.67em 0;}abbr[title]{border-bottom:1px dotted;}b,strong{font-weight:bold;}dfn{font-style:italic;}hr{-moz-box-sizing:content-box;box-sizing:content-box;height:0;}mark{background:#ff0;color:#000;}code,kbd,pre,samp{font-family:monospace,serif;font-size:1em;}pre{white-space:pre-wrap;}q{quotes:"\201C" "\201D" "\2018" "\2019";}small{font-size:80%;}sub,sup{font-size:75%;line-height:0;position:relative;vertical-align:baseline;}sup{top:-0.5em;}sub{bottom:-0.25em;}img{border:0;}svg:not(:root){overflow:hidden;}figure{margin:0;}fieldset{border:1px solid #c0c0c0;margin:0 2px;padding:0.35em 0.625em 0.75em;}legend{border:0;padding:0;}button,input,select,textarea{font-family:inherit;font-size:100%;margin:0;}button,input{line-height:normal;}button,select{text-transform:none;}button,html input[type="button"],input[type="reset"],input[type="submit"]{-webkit-appearance:button;cursor:pointer;}button[disabled],html input[disabled]{cursor:default;}input[type="checkbox"],input[type="radio"]{box-sizing:border-box;padding:0;}input[type="search"]{-webkit-appearance:textfield;-moz-box-sizing:content-box;-webkit-box-sizing:content-box;box-sizing:content-box;}input[type="search"]::-webkit-search-cancel-button,input[type="search"]::-webkit-search-decoration{-webkit-appearance:none;}button::-moz-focus-inner,input::-moz-focus-inner{border:0;padding:0;}textarea{overflow:auto;vertical-align:top;}table{border-collapse:collapse;border-spacing:0;} html, body, .container, .content-wrap { overflow: hidden; width: 100%; height: 100%; } .container { background: #373a47; } .menu-wrap a { color: #b8b7ad; } .menu-wrap a:hover, .menu-wrap a:focus { color: #c94e50; } .content-wrap { overflow-y: scroll; -webkit-overflow-scrolling: touch; } .content { position: relative; background: #b4bad2; } .content::before { position: absolute; top: 0; left: 0; z-index: 10; width: 100%; height: 100%; background: rgba(0,0,0,0.3); content: ''; opacity: 0; -webkit-transform: translate3d(100%,0,0); transform: translate3d(100%,0,0); -webkit-transition: opacity 0.4s, -webkit-transform 0s 0.4s; transition: opacity 0.4s, transform 0s 0.4s; } /* Menu Button */ .menu-button { position: fixed; bottom: 0; z-index: 1000; margin: 1em; padding: 0; width: 2.5em; height: 2.25em; border: none; text-indent: 2.5em; font-size: 1.5em; color: transparent; background: transparent; } .menu-button::before { position: absolute; top: 0.5em; right: 0.5em; bottom: 0.5em; left: 0.5em; background: linear-gradient(#373a47 20%, transparent 20%, transparent 40%, #373a47 40%, #373a47 60%, transparent 60%, transparent 80%, #373a47 80%); content: ''; } .menu-button:hover { opacity: 0.6; } /* Close Button */ .close-button { width: 16px; height: 16px; position: absolute; right: 1em; top: 1em; overflow: hidden; text-indent: 16px; border: none; z-index: 1001; background: transparent; color: transparent; } .close-button::before, .close-button::after { content: ''; position: absolute; width: 2px; height: 100%; top: 0; left: 50%; background: #888; } .close-button::before { -webkit-transform: rotate(45deg); transform: rotate(45deg); } .close-button::after { -webkit-transform: rotate(-45deg); transform: rotate(-45deg); } /* Menu */ .menu-wrap { position: absolute; bottom: 0; left: 0; z-index: 1001; width: 100%; height: 160px; font-size: 1.15em; -webkit-transform: translate3d(0,160px,0); transform: translate3d(0,160px,0); -webkit-transition: -webkit-transform 0.4s; transition: transform 0.4s; } .menu { position: absolute; width: 100%; z-index: 1000; text-align: center; top: 50%; padding: 0 1.5em; -webkit-transform: translate3d(0,-50%,0); transform: translate3d(0,-50%,0); } .icon-list a, .close-button { opacity: 0; -webkit-transform: translate3d(0,200px,0); transform: translate3d(0,200px,0); -webkit-transition: opacity 0.4s, -webkit-transform 0.4s; transition: opacity 0.4s, transform 0.4s; } .icon-list a { display: inline-block; padding: 0.8em; } .icon-list a i { vertical-align: middle; } .icon-list a span { display: inline-block; margin-left: 10px; font-size: 0.75em; vertical-align: middle; font-weight: 700; letter-spacing: 1px; } /* Morph Shape */ .morph-shape { position: absolute; width: 100%; width: calc(100% + 400px); height: 100%; top: 0; left: 0; fill: #373a47; -webkit-transition: -webkit-transform 0.4s; transition: transform 0.4s; -webkit-transform: translate3d(-400px,0,0); transform: translate3d(-400px,0,0); } /* Shown menu */ .show-menu .menu-wrap, .show-menu .icon-list a, .show-menu .close-button, .show-menu .morph-shape, .show-menu .content::before { -webkit-transform: translate3d(0,0,0); transform: translate3d(0,0,0); } .show-menu .menu-wrap, .show-menu .content::before { -webkit-transition-delay: 0s; transition-delay: 0s; } .show-menu .icon-list a, .show-menu .close-button, .show-menu .content::before { opacity: 1; } .show-menu .icon-list a:nth-child(2) { -webkit-transition-delay: 0.05s; transition-delay: 0.05s; } .show-menu .icon-list a:nth-child(3) { -webkit-transition-delay: 0.1s; transition-delay: 0.1s; } .show-menu .icon-list a:nth-child(4) { -webkit-transition-delay: 0.15s; transition-delay: 0.15s; } .show-menu .icon-list a:nth-child(5) { -webkit-transition-delay: 0.2s; transition-delay: 0.2s; } .show-menu .icon-list a:nth-child(6) { -webkit-transition-delay: 0.25s; transition-delay: 0.25s; } .show-menu .close-button { -webkit-transition-delay: 0.3s; transition-delay: 0.3s; } .show-menu .content::before { -webkit-transition: opacity 0.4s; transition: opacity 0.4s; } <link rel="stylesheet" type="text/css" href="https://tympanus.net/Development/OffCanvasMenuEffects/fonts/font-awesome-4.2.0/css/font-awesome.min.css" /> <script src="https://tympanus.net/Development/OffCanvasMenuEffects/js/snap.svg-min.js"></script> <div class="menu-wrap"> <nav class="menu"> <div class="icon-list"> <i class="fa fa-fw fa-star-o"></i><span>Favorites</span> <i class="fa fa-fw fa-bell-o"></i><span>Alerts</span> <i class="fa fa-fw fa-envelope-o"></i><span>Messages</span> <i class="fa fa-fw fa-comment-o"></i><span>Comments</span> <i class="fa fa-fw fa-bar-chart-o"></i><span>Analytics</span> <i class="fa fa-fw fa-newspaper-o"></i><span>Reading List</span> </div> </nav> <button class="close-button" id="close-button">Close Menu</button> <div class="morph-shape" id="morph-shape" data-morph-open="M0,100h1000V0c0,0-136.938,0-224,0C583,0,610.924,0,498,0C387,0,395,0,249,0C118,0,0,0,0,0V100z"> <svg xmlns="http://www.w3.org/2000/svg" width="100%" height="100%" viewBox="0 0 1000 100" preserveAspectRatio="none"> <path d="M0,100h1000l0,0c0,0-136.938,0-224,0c-193,0-170.235-1.256-278-35C399,34,395,0,249,0C118,0,0,100,0,100L0,100z"/> </svg> </div> </div> <button class="menu-button" id="open-button">Open Menu</button> <script src="https://tympanus.net/Development/OffCanvasMenuEffects/js/classie.js"></script> <script src="https://tympanus.net/Development/OffCanvasMenuEffects/js/main3.js"></script> Currently the Menu opens from bottom to top. My question is how is it possible to change the position of how the off canvas menu loads, default is bottom to top with wave effect convert to top to bottom, like this website: https://afriendofmine.nl How can this be achieved? I was tried to edit the menu but the result not good! I edit .menu-wrap class. I replace bottom: 0; with top: 0; as following: .menu-wrap { position: absolute; top: 0; //edited left: 0; z-index: 1001; width: 100%; height: 160px; font-size: 1.15em; -webkit-transform: translate3d(0,160px,0); transform: translate3d(0,160px,0); -webkit-transition: -webkit-transform 0.4s; transition: transform 0.4s; } After all, how can I make the menu to opens from top to bottom? like this website: https://afriendofmine.nl article,aside,details,figcaption,figure,footer,header,hgroup,main,nav,section,summary{display:block;}audio,canvas,video{display:inline-block;}audio:not([controls]){display:none;height:0;}[hidden]{display:none;}html{font-family:sans-serif;-ms-text-size-adjust:100%;-webkit-text-size-adjust:100%;}body{margin:0;}a:focus{outline:thin dotted;}a:active,a:hover{outline:0;}h1{font-size:2em;margin:0.67em 0;}abbr[title]{border-bottom:1px dotted;}b,strong{font-weight:bold;}dfn{font-style:italic;}hr{-moz-box-sizing:content-box;box-sizing:content-box;height:0;}mark{background:#ff0;color:#000;}code,kbd,pre,samp{font-family:monospace,serif;font-size:1em;}pre{white-space:pre-wrap;}q{quotes:"\201C" "\201D" "\2018" "\2019";}small{font-size:80%;}sub,sup{font-size:75%;line-height:0;position:relative;vertical-align:baseline;}sup{top:-0.5em;}sub{bottom:-0.25em;}img{border:0;}svg:not(:root){overflow:hidden;}figure{margin:0;}fieldset{border:1px solid #c0c0c0;margin:0 2px;padding:0.35em 0.625em 0.75em;}legend{border:0;padding:0;}button,input,select,textarea{font-family:inherit;font-size:100%;margin:0;}button,input{line-height:normal;}button,select{text-transform:none;}button,html input[type="button"],input[type="reset"],input[type="submit"]{-webkit-appearance:button;cursor:pointer;}button[disabled],html input[disabled]{cursor:default;}input[type="checkbox"],input[type="radio"]{box-sizing:border-box;padding:0;}input[type="search"]{-webkit-appearance:textfield;-moz-box-sizing:content-box;-webkit-box-sizing:content-box;box-sizing:content-box;}input[type="search"]::-webkit-search-cancel-button,input[type="search"]::-webkit-search-decoration{-webkit-appearance:none;}button::-moz-focus-inner,input::-moz-focus-inner{border:0;padding:0;}textarea{overflow:auto;vertical-align:top;}table{border-collapse:collapse;border-spacing:0;} html, body, .container, .content-wrap { overflow: hidden; width: 100%; height: 100%; } .container { background: #373a47; } .menu-wrap a { color: #b8b7ad; } .menu-wrap a:hover, .menu-wrap a:focus { color: #c94e50; } .content-wrap { overflow-y: scroll; -webkit-overflow-scrolling: touch; } .content { position: relative; background: #b4bad2; } .content::before { position: absolute; top: 0; left: 0; z-index: 10; width: 100%; height: 100%; background: rgba(0,0,0,0.3); content: ''; opacity: 0; -webkit-transform: translate3d(100%,0,0); transform: translate3d(100%,0,0); -webkit-transition: opacity 0.4s, -webkit-transform 0s 0.4s; transition: opacity 0.4s, transform 0s 0.4s; } /* Menu Button */ .menu-button { position: fixed; bottom: 0; z-index: 1000; margin: 1em; padding: 0; width: 2.5em; height: 2.25em; border: none; text-indent: 2.5em; font-size: 1.5em; color: transparent; background: transparent; } .menu-button::before { position: absolute; top: 0.5em; right: 0.5em; bottom: 0.5em; left: 0.5em; background: linear-gradient(#373a47 20%, transparent 20%, transparent 40%, #373a47 40%, #373a47 60%, transparent 60%, transparent 80%, #373a47 80%); content: ''; } .menu-button:hover { opacity: 0.6; } /* Close Button */ .close-button { width: 16px; height: 16px; position: absolute; right: 1em; top: 1em; overflow: hidden; text-indent: 16px; border: none; z-index: 1001; background: transparent; color: transparent; } .close-button::before, .close-button::after { content: ''; position: absolute; width: 2px; height: 100%; top: 0; left: 50%; background: #888; } .close-button::before { -webkit-transform: rotate(45deg); transform: rotate(45deg); } .close-button::after { -webkit-transform: rotate(-45deg); transform: rotate(-45deg); } /* Menu */ .menu-wrap { position: absolute; top: 0; //edited left: 0; z-index: 1001; width: 100%; height: 160px; font-size: 1.15em; -webkit-transform: translate3d(0,160px,0); transform: translate3d(0,160px,0); -webkit-transition: -webkit-transform 0.4s; transition: transform 0.4s; } .menu { position: absolute; width: 100%; z-index: 1000; text-align: center; top: 50%; padding: 0 1.5em; -webkit-transform: translate3d(0,-50%,0); transform: translate3d(0,-50%,0); } .icon-list a, .close-button { opacity: 0; -webkit-transform: translate3d(0,200px,0); transform: translate3d(0,200px,0); -webkit-transition: opacity 0.4s, -webkit-transform 0.4s; transition: opacity 0.4s, transform 0.4s; } .icon-list a { display: inline-block; padding: 0.8em; } .icon-list a i { vertical-align: middle; } .icon-list a span { display: inline-block; margin-left: 10px; font-size: 0.75em; vertical-align: middle; font-weight: 700; letter-spacing: 1px; } /* Morph Shape */ .morph-shape { position: absolute; width: 100%; width: calc(100% + 400px); height: 100%; top: 0; left: 0; fill: #373a47; -webkit-transition: -webkit-transform 0.4s; transition: transform 0.4s; -webkit-transform: translate3d(-400px,0,0); transform: translate3d(-400px,0,0); } /* Shown menu */ .show-menu .menu-wrap, .show-menu .icon-list a, .show-menu .close-button, .show-menu .morph-shape, .show-menu .content::before { -webkit-transform: translate3d(0,0,0); transform: translate3d(0,0,0); } .show-menu .menu-wrap, .show-menu .content::before { -webkit-transition-delay: 0s; transition-delay: 0s; } .show-menu .icon-list a, .show-menu .close-button, .show-menu .content::before { opacity: 1; } .show-menu .icon-list a:nth-child(2) { -webkit-transition-delay: 0.05s; transition-delay: 0.05s; } .show-menu .icon-list a:nth-child(3) { -webkit-transition-delay: 0.1s; transition-delay: 0.1s; } .show-menu .icon-list a:nth-child(4) { -webkit-transition-delay: 0.15s; transition-delay: 0.15s; } .show-menu .icon-list a:nth-child(5) { -webkit-transition-delay: 0.2s; transition-delay: 0.2s; } .show-menu .icon-list a:nth-child(6) { -webkit-transition-delay: 0.25s; transition-delay: 0.25s; } .show-menu .close-button { -webkit-transition-delay: 0.3s; transition-delay: 0.3s; } .show-menu .content::before { -webkit-transition: opacity 0.4s; transition: opacity 0.4s; } <link rel="stylesheet" type="text/css" href="https://tympanus.net/Development/OffCanvasMenuEffects/fonts/font-awesome-4.2.0/css/font-awesome.min.css" /> <script src="https://tympanus.net/Development/OffCanvasMenuEffects/js/snap.svg-min.js"></script> <div class="menu-wrap"> <nav class="menu"> <div class="icon-list"> <i class="fa fa-fw fa-star-o"></i><span>Favorites</span> <i class="fa fa-fw fa-bell-o"></i><span>Alerts</span> <i class="fa fa-fw fa-envelope-o"></i><span>Messages</span> <i class="fa fa-fw fa-comment-o"></i><span>Comments</span> <i class="fa fa-fw fa-bar-chart-o"></i><span>Analytics</span> <i class="fa fa-fw fa-newspaper-o"></i><span>Reading List</span> </div> </nav> <button class="close-button" id="close-button">Close Menu</button> <div class="morph-shape" id="morph-shape" data-morph-open="M0,100h1000V0c0,0-136.938,0-224,0C583,0,610.924,0,498,0C387,0,395,0,249,0C118,0,0,0,0,0V100z"> <svg xmlns="http://www.w3.org/2000/svg" width="100%" height="100%" viewBox="0 0 1000 100" preserveAspectRatio="none"> <path d="M0,100h1000l0,0c0,0-136.938,0-224,0c-193,0-170.235-1.256-278-35C399,34,395,0,249,0C118,0,0,100,0,100L0,100z"/> </svg> </div> </div> <button class="menu-button" id="open-button">Open Menu</button> <script src="https://tympanus.net/Development/OffCanvasMenuEffects/js/classie.js"></script> <script src="https://tympanus.net/Development/OffCanvasMenuEffects/js/main3.js"></script>
This is what you need? .morph-shape>svg { transform:rotate3d(1, 0, 0, 180deg); } https://jsfiddle.net/g4pmr6ez/1/
Make hamburger menu fadeout work
I am doing a "hamburger" menu, responsive style, with a menu that will cover the page the viewer is at. I got all HTML/CSS figured out, but I wanted to add fade in and fade out effects. Fade in works with jquery code but the menu isn't fading out. Already tried some ideas that were on SO but none works. Any help? Fiddle: https://jsfiddle.net/f19kz640/ Sorry for bad eng... HTML <header> <div id="topbar"> <!-- top bar --> <div id="nav-icon"> <span></span> <span></span> <span></span> <span></span> </div> <div id="menu"> <ul> <li>Link1</li> <li>Link2</li> <li>Link3</li> <li>Link4</li> <li>Link5</li> </ul> </div> </div> </header> CSS body{ background-color: #000; } #menu{ z-index: 5; width: 100%; height: 100%; background-color: rgba(0,0,0, 0.95); position: fixed; font-size: 1.5em; text-align: center; right: 0px; top: 0px; opacity: 0; display: table; } .hidden{ display: none; visibility: none; } #menu ul{ margin: 0; padding: 0; z-index: 10; width: 100%; height: 100%; display: table-cell; vertical-align: middle; } #menu ul li{ cursor: pointer; text-decoration: none; } #menu ul li:hover{ background-color: #006973; -webkit-transition: .15s ease-in-out; -moz-transition: .15s ease-in-out; -o-transition: .15s ease-in-out; transition: .15s ease-in-out; } #menu ul a{ letter-spacing: 5px; text-align: center; margin-left: auto; margin-right: auto; color: #fff; list-style: none; text-transform: uppercase; padding: 0px; line-height: 75px; padding: 10px 700px; text-decoration: none; } #menu ul a:hover{ text-decoration: none; color: #fff ; } #nav-icon { z-index: 20; width: 50px; height: 35px; position: relative; margin: 35px 30px; -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; } #nav-icon span { display: block; position: absolute; height: 5px; width: 40px; background: #bada33; 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; } /* Icon 3 */ #nav-icon span:nth-child(1) { top: 0px; } #nav-icon span:nth-child(2),#nav-icon span:nth-child(3) { top: 12px; } #nav-icon span:nth-child(4) { top: 24px; } #nav-icon.open span:nth-child(1) { top: 8px; width: 0%; left: 50%; } #nav-icon.open span:nth-child(2) { -webkit-transform: rotate(45deg); -moz-transform: rotate(45deg); -o-transform: rotate(45deg); transform: rotate(45deg); } #nav-icon.open span:nth-child(3) { -webkit-transform: rotate(-45deg); -moz-transform: rotate(-45deg); -o-transform: rotate(-45deg); transform: rotate(-45deg); } #nav-icon.open span:nth-child(4) { top: 8px; width: 0%; left: 50%; } Javascript/JQuery $(document).ready(function(){ $('#nav-icon').click(function(){ $(this).toggleClass('open'); if($('#menu').css('opacity') == '0'){ $('#menu').css('opacity','1'); $('#menu').fadeIn(300).css('display','table'); }else{ $('#menu').css('opacity','0'); $('#menu').fadeOut(300).css('display','none'); } }); });
You could easily simplify things a great deal: $(document).ready(function(){ $('#nav-icon').click(function(){ $(this).toggleClass('open'); $('#menu').fadeToggle(300); }); }); Updated Fiddle There's no reason to play with opacity properties or display properties, it's all part of the jQuery fade() function, which you can merely toggle.
jquery combining multiple variables (elements set as vars)
I am trying to learn a bit of Javascript/JQuery for school and got stuck on something I don't quite understand. Everything in my function "works" as I wanted it to, but it feels odd that I have to list each of my selectors on a different line in order to remove all classes from each. I've tried .merge and .add as suggestions i read on other posts, but I couldn't make it work (possibly not implementing it right) and I was hoping someone can show me how to do it and maybe explain why something like this doesn't work: $(menuWrapper, menuTrigger, menuIcon, contentWrapper).removeClass(); This is my entire function, along with it working(just desktop css) on jsFiddle // JavaScript Document function toggleNavSettings(swipeDirection) { menuWrapper = $("#menu-wrapper"); menuIcon = $('#menu-icon'); menuTrigger = $("#menu-trigger-wrapper"); contentWrapper = $("#custom-wrapper"); if(menuWrapper.width() > 199){//if nav expanded if($( document ).width() > 480){//if screen is not mobile menuWrapper.removeClass(); menuTrigger.removeClass(); menuIcon.removeClass(); contentWrapper.removeClass(); menuWrapper.addClass("menu-collapsed");//collapse the emenu menuTrigger.addClass("menu-trigger-wrapper-d-closed");//swing the trigger menuIcon.addClass("open-d"); contentWrapper.addClass("closed-d");//collapse the content pane } else{//if screen is Mobile menuWrapper.removeClass(); menuTrigger.removeClass(); menuIcon.removeClass(); contentWrapper.removeClass(); menuWrapper.addClass("menu-collapsed-m");//expand menu for desktop menuTrigger.addClass("menu-trigger-wrapper-d-closed");//swing the trigger menuIcon.addClass("open-d"); contentWrapper.addClass("closed-d"); } } else{//if NAV is collapsed if($( document ).width() > 480){//if screen is not mobile menuWrapper.removeClass(); menuTrigger.removeClass(); menuIcon.removeClass(); contentWrapper.removeClass(); menuWrapper.addClass("menu-expanded");//expand menu contentWrapper.addClass("open-m");//expand the content pane } else{//if window screen is MOBILE menuWrapper.removeClass(); menuTrigger.removeClass(); menuIcon.removeClass(); contentWrapper.removeClass(); menuWrapper.addClass("menu-expanded-m");//expand the menu menuTrigger.addClass("menu-trigger-wrapper-m-open");//swing the trigger menuIcon.addClass("open-m"); contentWrapper.addClass("open-d");//expand the content pane } } } $(document).ready(function() { var menuTrigger = $("#menu-trigger-wrapper"); menuTrigger.click(function() { toggleNavSettings(null); }); }); https://jsfiddle.net/o5ogex6q/1/ Thanks in advance!
You could use something like this $('#menu-wrapper, #menu-icon, #menu-trigger-wrapper, #custom-wrapper').removeClass(); EDIT You can keep your variables and use following syntax object.selector to get the ID value. The only "messy" thing are the string commas. $(menuWrapper.selector+","+ menuTrigger.selector+","+menuIcon.selector+","+ contentWrapper.selector).removeClass();
This is riding the line of a duplicate question to: How to combine two jQuery results One slight difference is you'd have to pass each collection individually, eg: var allMenuObjects = menuWrapper.add(menuIcon).add(menuTrigger).add(contentWrapper); Hopefully this helps and I appreciate your efforts in understanding how to use jQuery efficiently. (eg without engaging the selector engine repeatedly)
Try the below code, You can use toggleClass Find more information about toggleClass function toggleNavSettings(swipeDirection) { menuWrapper = $("#menu-wrapper"); menuIcon = $('#menu-icon'); menuTrigger = $("#menu-trigger-wrapper"); contentWrapper = $("#custom-wrapper"); if ($(document).width() > 480) { //if screen is not mobile menuWrapper.toggleClass("menu-collapsed"); menuTrigger.toggleClass("menu-trigger-wrapper-d-closed"); menuIcon.toggleClass("open-d"); contentWrapper.toggleClass("closed-d"); } else { //if screen is Mobile menuWrapper.toggleClass("menu-collapsed-m"); menuTrigger.toggleClass("menu-trigger-wrapper-d-closed"); menuIcon.toggleClass("open-d"); contentWrapper.toggleClass("closed-d"); } } $(document).ready(function() { var menuTrigger = $("#menu-trigger-wrapper"); menuTrigger.click(function() { toggleNavSettings(null); }); }); #charset"utf-8"; /* CSS Document */ html { width: 100%; height: 100%; padding: 0; margin: 0; } body { background: #121212; color: #00c4e2; padding: 0; margin: 0; width: 100%; height: 100%; } .template-wrapper { position: relative; left: 0px; top: 0px; width: 100%; height: 100%; } #custom-wrapper, #custom-wrapper.open-d { padding-left: 210px; transition: all 0.4s; } #custom-wrapper.closed-d { padding-left: 10px; } .content-page { position: relative!important; } #menu-wrapper { background: url(../images/menu_pattern_1.png); background-repeat: repeat; border-right: #00c4e2 10px solid; position: fixed; display: block; top: 0; left: 0; width: 200px; overflow-y: auto; height: 100%; transition: all 0.4s; z-index: 1001; } .menu-expanded { width: 200px; } .menu-collapsed { width: 0px!important; } .menu-collapsed-m { width: 0px!important; } .menu-wrapper.scroll { width: 210px; border-right: none; } #menu-trigger-wrapper { transition: all 0.4s; position: fixed; display: block; top: 0px; left: 209px; background: #00c4e2; width: 48px; height: 48px; color: #fff; cursor: pointer; z-index: 1002; } .menu-trigger-wrapper-d-closed { left: 9px!important; } .menu-trigger { width: 100%; height: 100%; position: relative; } /*MENU ANIMATIONS*/ /* Icon 1 */ #menu-icon { width: 86%; height: 100%; position: relative; margin: 10px 0px 0px 1px; -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; } #menu-icon span { display: block; position: absolute; height: 5px; width: 100%; background: #fff; 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 span:nth-child(1) { top: 0px; } #menu-icon span:nth-child(1), #menu-icon.open-d span:nth-child(1) { top: 12px; -webkit-transform: rotate(135deg); -moz-transform: rotate(135deg); -o-transform: rotate(135deg); transform: rotate(135deg); } #menu-icon span:nth-child(2) { opacity: 0; top: 12px; } #menu-icon.open-d span:nth-child(1) { opacity: 100; } #menu-icon span:nth-child(3), #menu-icon.open-d span:nth-child(3), #menu-icon.open-m span:nth-child(3) { top: 12px; -webkit-transform: rotate(-135deg); -moz-transform: rotate(-135deg); -o-transform: rotate(-135deg); transform: rotate(-135deg); } #menu-icon.open-d span:nth-child(1) { top: 0px; -webkit-transform: rotate(0deg); -moz-transform: rotate(-0deg); -o-transform: rotate(-0deg); transform: rotate(-0deg); } #menu-icon.open-d span:nth-child(2) { top: 12px; opacity: 100; } #menu-icon.open-d span:nth-child(3) { top: 24px; -webkit-transform: rotate(0deg); -moz-transform: rotate(-0deg); -o-transform: rotate(-0deg); transform: rotate(-0deg); } .content-page { margin-left: 250px; } <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script> <div id="menu-trigger-wrapper"> <div id="menu-icon"> <span></span> <span></span> <span></span> </div> </div> <div id="menu-wrapper" data-mcs-theme="inset"> <div class="menu-container"> Link 1 <br> Link 2 <br> Link 3 <br> </div> </div> <div id="custom-wrapper">blah blah</div>