javascript - Make the menu button slide with the menu -
i trying make side menu bar toggles press of menu button, issue i'm facing here want menu button slide left side menu slides off , again move same position when menu slides in, hoping so..
here code please let me know if went wrong somewere,
.html
<html> <head> <title>slds nav-bar</title> <link rel="stylesheet" href="//code.jquery.com/ui/1.12.1/themes/smoothness/jquery-ui.css"/> <style> /*basic styling*/ html, body { height: 100%; background-color: #eee; } #header{ margin-left: 218px; width: 59.88em; margin-bottom: -3em; } .menu-button{ font-size:2em; } /*additional slds styling*/ .slds-nav--size{ width: 218px; border-right: 1px solid #d8dde6; background:white; height: 50.96em; } /*media queries*/ @media screen , (max-width: 768px) { /* mobile phones: */ [class*="slds-nav--size"] { transform: translate(-218px); } } </style> <!--script's gose here--> <script src="//code.jquery.com/jquery-2.1.4.min.js"></script> <script src="//code.jquery.com/jquery-1.12.4.js"></script> <script src="//code.jquery.com/ui/1.12.1/jquery-ui.js"></script> <script> // ========================================================================== // animate menu toggle // ========================================================================== $(document).ready(function(){ $(".menu-button").click(function(){ $(".toggle-menu").toggle("drop",300); }); }); </script> </head> <body> <header id="header"> <div class=""> <a class="menu-button">☰</a> </div> </header> <div class="slds-grid slds-grid--vertical slds-navigation-list--vertical slds-navigation-list--vertical-inverse slds-nav--size toggle-menu"> <h2 class="slds-text-title--caps slds-p-around--medium" id="search-results">search results</h2> <ul> <li class="slds-is-active"><a href="javascript:void(0);" class="slds-navigation-list--vertical__action slds-text-link--reset" aria-describedby="search-results">top results</a></li> <li><a href="javascript:void(0);" class="slds-navigation-list--vertical__action slds-text-link--reset" aria-describedby="search-results">accounts</a></li> <li><a href="javascript:void(0);" class="slds-navigation-list--vertical__action slds-text-link--reset" aria-describedby="search-results">contacts</a></li> <li><a href="javascript:void(0);" class="slds-navigation-list--vertical__action slds-text-link--reset" aria-describedby="search-results">opportunities</a></li> <li><a href="javascript:void(0);" class="slds-navigation-list--vertical__action slds-text-link--reset" aria-describedby="search-results">leads</a></li> <li><a href="javascript:void(0);" class="slds-navigation-list--vertical__action slds-text-link--reset" aria-describedby="search-results">groups</a></li> <li><a href="javascript:void(0);" class="slds-navigation-list--vertical__action slds-text-link--reset" aria-describedby="search-results">files</a></li> <li><a href="javascript:void(0);" class="slds-navigation-list--vertical__action slds-text-link--reset" aria-describedby="search-results">dashboards</a></li> <li><a href="javascript:void(0);" class="slds-navigation-list--vertical__action slds-text-link--reset" aria-describedby="search-results">reports</a></li> <li><a href="javascript:void(0);" class="slds-navigation-list--vertical__action slds-text-link--reset" aria-describedby="search-results">feeds</a></li> </ul> <h2 class="slds-text-title--caps slds-p-around--medium" id="external-results">external results</h2> <ul> <li><a href="javascript:void(0);" class="slds-navigation-list--vertical__action slds-text-link--reset" aria-describedby="external-results">app one</a></li> <li><a href="javascript:void(0);" class="slds-navigation-list--vertical__action slds-text-link--reset" aria-describedby="external-results">app two</a></li> <li><a href="javascript:void(0);" class="slds-navigation-list--vertical__action slds-text-link--reset" aria-describedby="external-results">app three</a></li> </ul> </div> </body> </html>
when menu clicked, add class header. class in css defines margin-left
10px. when menu clicked again, goes original position.
$(document).ready(function() { $(".menu-button").click(function() { $(".toggle-menu").toggle("drop", 300); $("#header").toggleclass("to-the-left"); }); });
html, body { height: 100%; background-color: #eee; } #header { margin-left: 218px; width: 59.88em; margin-bottom: -3em; transition: margin-left 0.3s ease-in 0s; } #header.to-the-left { margin-left: 10px; } .menu-button { font-size: 2em; } /*additional slds styling*/ .slds-nav--size { width: 218px; border-right: 1px solid #d8dde6; background: white; height: 50.96em; } /*media queries*/ @media screen , (max-width: 400px) { /* mobile phones: */ [class*="slds-nav--size"] { transform: translate(-218px); } }
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script> <script src="https://code.jquery.com/ui/1.12.1/jquery-ui.js"></script> <header id="header"> <div class=""> <a class="menu-button">☰</a> </div> </header> <div class="slds-grid slds-grid--vertical slds-navigation-list--vertical slds-navigation-list--vertical-inverse slds-nav--size toggle-menu"> <h2 class="slds-text-title--caps slds-p-around--medium" id="search-results">search results</h2> <ul> <li class="slds-is-active"><a href="javascript:void(0);" class="slds-navigation-list--vertical__action slds-text-link--reset" aria-describedby="search-results">top results</a></li> <li><a href="javascript:void(0);" class="slds-navigation-list--vertical__action slds-text-link--reset" aria-describedby="search-results">accounts</a></li> <li><a href="javascript:void(0);" class="slds-navigation-list--vertical__action slds-text-link--reset" aria-describedby="search-results">contacts</a></li> <li><a href="javascript:void(0);" class="slds-navigation-list--vertical__action slds-text-link--reset" aria-describedby="search-results">opportunities</a></li> <li><a href="javascript:void(0);" class="slds-navigation-list--vertical__action slds-text-link--reset" aria-describedby="search-results">leads</a></li> <li><a href="javascript:void(0);" class="slds-navigation-list--vertical__action slds-text-link--reset" aria-describedby="search-results">groups</a></li> <li><a href="javascript:void(0);" class="slds-navigation-list--vertical__action slds-text-link--reset" aria-describedby="search-results">files</a></li> <li><a href="javascript:void(0);" class="slds-navigation-list--vertical__action slds-text-link--reset" aria-describedby="search-results">dashboards</a></li> <li><a href="javascript:void(0);" class="slds-navigation-list--vertical__action slds-text-link--reset" aria-describedby="search-results">reports</a></li> <li><a href="javascript:void(0);" class="slds-navigation-list--vertical__action slds-text-link--reset" aria-describedby="search-results">feeds</a></li> </ul> <h2 class="slds-text-title--caps slds-p-around--medium" id="external-results">external results</h2> <ul> <li><a href="javascript:void(0);" class="slds-navigation-list--vertical__action slds-text-link--reset" aria-describedby="external-results">app one</a></li> <li><a href="javascript:void(0);" class="slds-navigation-list--vertical__action slds-text-link--reset" aria-describedby="external-results">app two</a></li> <li><a href="javascript:void(0);" class="slds-navigation-list--vertical__action slds-text-link--reset" aria-describedby="external-results">app three</a></li> </ul> </div>
Comments
Post a Comment