在构建新网站时,我尝试使用位于here.的Codrops的幻灯片/推送菜单
据我所知,我已将所有正确的代码放入我的文件中,但无法打开菜单。
如果我将我的按钮类更改为showRight,我可以打开菜单但是当将其更改为showRightPush以使菜单向左推动身体时它不起作用。
有人可以看一下位于here,的jsfiddle来帮我弄清楚我做错了吗?
我的代码也在下面。
谢谢!
// ===== Side Menu Hide Show
//=====================================================================================================
$(function() {
var menuVisible = false;
$('#showRight').click(function() {
if (menuVisible) {
$('.cbp-spmenu').css({
'display': 'none'
});
menuVisible = false;
return;
}
$('.cbp-spmenu').css({
'display': 'block'
});
menuVisible = true;
});
var menuVisible = false;
$('#close').click(function() {
if (menuVisible) {
$('.cbp-spmenu').css({
'display': 'none'
});
menuVisible = false;
return;
}
$('.cbp-spmenu').css({
'display': 'block'
});
menuVisible = true;
});
});
/*!
* classie - class helper functions
* from bonzo https://github.com/ded/bonzo
*
* classie.has( elem, 'my-class' ) -> true/false
* classie.add( elem, 'my-new-class' )
* classie.remove( elem, 'my-unwanted-class' )
* classie.toggle( elem, 'my-class' )
*/
/*jshint browser: true, strict: true, undef: true */
( function( window ) {
'use strict';
// class helper functions from bonzo https://github.com/ded/bonzo
function classReg( className ) {
return new RegExp("(^|\\s+)" + className + "(\\s+|$)");
}
// classList support for class management
// altho to be fair, the api sucks because it won't accept multiple classes at once
var hasClass, addClass, removeClass;
if ( 'classList' in document.documentElement ) {
hasClass = function( elem, c ) {
return elem.classList.contains( c );
};
addClass = function( elem, c ) {
elem.classList.add( c );
};
removeClass = function( elem, c ) {
elem.classList.remove( c );
};
}
else {
hasClass = function( elem, c ) {
return classReg( c ).test( elem.className );
};
addClass = function( elem, c ) {
if ( !hasClass( elem, c ) ) {
elem.className = elem.className + ' ' + c;
}
};
removeClass = function( elem, c ) {
elem.className = elem.className.replace( classReg( c ), ' ' );
};
}
function toggleClass( elem, c ) {
var fn = hasClass( elem, c ) ? removeClass : addClass;
fn( elem, c );
}
window.classie = {
// full names
hasClass: hasClass,
addClass: addClass,
removeClass: removeClass,
toggleClass: toggleClass,
// short names
has: hasClass,
add: addClass,
remove: removeClass,
toggle: toggleClass
};
})( window );
var menuLeft = document.getElementById( 'cbp-spmenu-s1' ),
menuRight = document.getElementById( 'cbp-spmenu-s2' ),
menuTop = document.getElementById( 'cbp-spmenu-s3' ),
menuBottom = document.getElementById( 'cbp-spmenu-s4' ),
showLeft = document.getElementById( 'showLeft' ),
showRight = document.getElementById( 'showRight' ),
showTop = document.getElementById( 'showTop' ),
showBottom = document.getElementById( 'showBottom' ),
showLeftPush = document.getElementById( 'showLeftPush' ),
showRightPush = document.getElementById( 'showRightPush' ),
body = document.body;
showLeft.onclick = function() {
classie.toggle( this, 'active' );
classie.toggle( menuLeft, 'cbp-spmenu-open' );
disableOther( 'showLeft' );
};
showRight.onclick = function() {
classie.toggle( this, 'active' );
classie.toggle( menuRight, 'cbp-spmenu-open' );
disableOther( 'showRight' );
};
showTop.onclick = function() {
classie.toggle( this, 'active' );
classie.toggle( menuTop, 'cbp-spmenu-open' );
disableOther( 'showTop' );
};
showBottom.onclick = function() {
classie.toggle( this, 'active' );
classie.toggle( menuBottom, 'cbp-spmenu-open' );
disableOther( 'showBottom' );
};
showLeftPush.onclick = function() {
classie.toggle( this, 'active' );
classie.toggle( body, 'cbp-spmenu-push-toright' );
classie.toggle( menuLeft, 'cbp-spmenu-open' );
disableOther( 'showLeftPush' );
};
showRightPush.onclick = function() {
classie.toggle( this, 'active' );
classie.toggle( body, 'cbp-spmenu-push-toleft' );
classie.toggle( menuRight, 'cbp-spmenu-open' );
disableOther( 'showRightPush' );
};
function disableOther( button ) {
if( button !== 'showLeft' ) {
classie.toggle( showLeft, 'disabled' );
}
if( button !== 'showRight' ) {
classie.toggle( showRight, 'disabled' );
}
if( button !== 'showTop' ) {
classie.toggle( showTop, 'disabled' );
}
if( button !== 'showBottom' ) {
classie.toggle( showBottom, 'disabled' );
}
if( button !== 'showLeftPush' ) {
classie.toggle( showLeftPush, 'disabled' );
}
if( button !== 'showRightPush' ) {
classie.toggle( showRightPush, 'disabled' );
}
}
// ===== Side Menu Drop Downs
//=====================================================================================================
$(document).ready(function() {
$('.parent').click(function() {
$(".parent").not(this).find(".sub-nav").removeClass('visible').slideUp();
$(this).find('.sub-nav').toggleClass('visible').slideToggle();
});
});

/***** PAGE SETUP *****
***************************************************************/
a,abbr,acronym,address,applet,article,aside,audio,b,big,blockquote,body,canvas,caption,center,cite,code,dd,del,details,dfn,dialog,div,dl,dt,em,embed,fieldset,figcaption,figure,font,footer,form,h1,h2,h3,h4,h5,h6,header,hgroup,hr,html,i,iframe,img,ins,kbd,label,legend,li,main,mark,menu,meter,nav,object,ol,output,p,pre,progress,q,rp,rt,ruby,s,samp,section,small,span,strike,strong,sub,summary,sup,table,tbody,td,tfoot,th,thead,time,tr,tt,u,ul,var,video,xmp {
border: 0;
margin: 0;
padding: 0;
font-size: 100%;
}
html,
body {
height: 100%;
}
article,
aside,
details,
figcaption,
figure,
footer,
header,
hgroup,
main,
menu,
nav,
section {
display: block;
}
b,
strong {
font-weight: bold;
}
img {
display: block;
width: 100%;
color: transparent;
font-size: 0;
vertical-align: middle;
-ms-interpolation-mode: bicubic;
}
ul,
ol {
list-style: none;
}
li {
display: list-item;
}
table {
border-collapse: collapse;
border-spacing: 0;
}
th,
td,
caption {
font-weight: normal;
vertical-align: top;
text-align: left;
}
q {
quotes: none;
}
q:before,
q:after {
content: "";
content: none;
}
body {
font: 18px / 1.5 'Source Sans Pro', sans-serif;
color: #384554;
font-weight: 300;
}
hr {
border-top: 1px solid #eee ;
clear: both;
height: 0;
width: 80%;
margin: 30px 0 0 0;
padding: 0 10px;
}
i {
color: rgba(22, 156, 208, 0.83);
}
h1 { font-size: 25px; }
h2 { font-size: 23px; }
h3 { font-size: 21px; }
h4 { font-size: 19px; }
h5 { font-size: 17px; }
h6 { font-size: 15px; }
ol {
list-style: decimal;
}
ul {
list-style: disc;
}
li {
margin-left: 30px;
}
h1,
h2,
h3,
h4,
h5,
h6{
font-family: 'Roboto Condensed', sans-serif;
}
p,
dl,
hr,
ol,
ul,
pre,
table,
address,
fieldset,
figure {
font-family: 'Source Sans Pro', sans-serif;
}
body {
background: #fff;
color: #4c5867;
text-align: center;
}
a {
font-family: 'Roboto Condensed', sans-serif;
color: #4c5867;
text-decoration: none;
}
a:hover {
text-decoration: none;
color: #169CD0;
}
.button {
display: inline-block;
background-color: #169CD0;
padding: 10px 20px;
color: #fff;
border-radius: 5px;
font-family: 'Roboto Condensed', sans-serif;
font-size: 20px;
font-weight: 300;
text-transform: uppercase;
}
.button-orange {
display: inline-block;
background-color: #FF9C00;
padding: 10px 20px;
color: #fff;
border-radius: 5px;
font-family: 'Roboto Condensed', sans-serif;
font-size: 20px;
font-weight: 300;
text-transform: uppercase;
margin: 25px 0 0 0;
}
.btn-left {
float: left;
}
.button:hover {
background-color: rgba(22, 156, 208, 0.83);
color: #fff;
}
.button i, .button-orange i {
color: #fff;
}
.hideme {
opacity: 0;
}
.hideme-side {
opacity: 0;
position: relative;
}
/*animation element sliding left*/
.hideme-side.slide-left {
opacity: 0;
-moz-transition: all 500ms linear;
-webkit-transition: all 500ms linear;
-o-transition: all 500ms linear;
transition: all 500ms linear;
-moz-transform: translate3d(-100px, 0px, 0px);
-webkit-transform: translate3d(-100px, 0px, 0px);
-o-transform: translate(-100px, 0px);
-ms-transform: translate(-100px, 0px);
transform: translate3d(-100px, 0px, 0px);
}
.hideme-side.slide-left.in-view {
opacity: 1;
-moz-transform: translate3d(0px, 0px, 0px);
-webkit-transform: translate3d(0px, 0px, 0px);
-o-transform: translate(0px, 0px);
-ms-transform: translate(0px, 0px);
transform: translate3d(0px, 0px, 0px);
}
/***** PUSH PULL CLASSES *****
***************************************************************/
.grid-container > hr {
margin-left: 10px;
margin-right: 10px;
}
div[class*="push-"] section {
/**background: #dec;**/
}
div[class*="pull-"] section {
/**background: #fcd;**/
}
.dynamic-px-width {
/**display: block;**/
}
/***** Above Header *****
****************************************************************************/
.pre-above-head {
background-color: #f2f2f2;
height: 30px;
}
#above-head {
margin: 0;
padding: 0;
height: 30px;
}
.above-head-left {
text-align: left;
float: left;
font-size: 14px;
padding-right: 25px;
font-weight: 300;
padding: 4px 0 0 0;
}
.above-head-contacts {
float: right;
padding: 0 0 0 20px;
}
.social-bar a {
display: inline-block;
float: right;
width: 1.3em;
height: 1.3em;
margin: 3px 5px 0 5px;
color: #4c5867;
background-color: #fff;
-webkit-border-radius: 50%;
-moz-border-radius: 50%;
border-radius: 50%;
}
.social-bar i {
color: #4c5867;
}
.social-bar i:hover {
color: #169CD0;
transition: all .25s ease;
}
/***** HEADER *****
****************************************************************************/
.pre-head {
position: absolute;
width: 100%;
left: 0;
right: 0;
margin: 0 auto;
}
#head_container {
display: block;
padding: 0;
}
.compact {
margin: 0;
padding: 0;
}
.head {
padding: 20px 0 5px 0;
}
#header {
height: auto;
position: relative;
}
.menu-hamburger {
margin: 0 0 px 0;
}
.fatnav_header #header_logo {
position: absolute;
z-index: 1001;
margin: -5px 0 0 0;
}
#fat_nav {
padding: 0;
text-align: right;
}
.fatnav_header ul,
.fatnav_header li {
box-sizing: border-box;
list-style: none;
padding: 0;
margin: 0;
}
#nav li {
padding: 0;
width: 100%;
text-align: left;
font-weight: 400;
color: #fff;
white-space: nowrap;
}
.parent a{
border-bottom: 1px solid #fff;
}
.sub-nav {
background: rgba(18, 107, 142, 0.22);
display: block;
overflow: hidden;
-webkit-box-shadow: inset 0px -4px 7px 2px rgba(0,0,0,0.11);
-moz-box-shadow: inset 0px -4px 7px 2px rgba(0,0,0,0.11);
box-shadow: inset 0px -4px 7px 2px rgba(0,0,0,0.11);
}
.sub-nav li a {
padding: 10px 0 10px 30px;
border: none;
}
.nav-top i {
color: #fff;
}
#showRightPush {
background: none;
border: none;
}
#showRightPush img {
width: 95px;
padding: 0;
float: right;
}
#close {
background: none;
border: none;
display: block;
margin: 0 auto;
padding: 21px 0 0 0;
width: 100%;
}
#close img {
width: 25px;
float: right;
padding: 0 20px 0 0;
}
.cbp-spmenu {
background: #169CD0;
position: fixed;
overflow: auto;
}
.cbp-spmenu h3 {
color: #afdefa;
font-size: 1.9em;
padding: 20px;
margin: 0;
font-weight: 300;
background: #169CD0;
}
.cbp-spmenu a {
display: block;
color: #fff;
font-size: 1.1em;
font-weight: 300;
}
.cbp-spmenu a:hover {
background: #258ecd;
}
.cbp-spmenu a:active {
background: #afdefa;
color: #47a3da;
}
/* Orientation-dependent styles for the content of the menu */
.cbp-spmenu-vertical {
width: 240px;
height: 100%;
top: 0;
z-index: 100;
}
.cbp-spmenu-vertical a {
padding: 1em;
}
.cbp-spmenu-horizontal {
width: 100%;
height: 150px;
left: 0;
z-index: 100;
overflow: hidden;
}
.cbp-spmenu-horizontal h3 {
height: 100%;
width: 20%;
float: left;
}
.cbp-spmenu-horizontal a {
float: left;
width: 20%;
padding: 0.8em;
border-left: 1px solid #258ecd;
}
/* Vertical menu that slides from the left or right */
.cbp-spmenu-right {
display: none;
right: 0px;
}
.cbp-spmenu-right.cbp-spmenu-open {
right: 0px;
}
/* Transitions */
.cbp-spmenu,
.cbp-spmenu-push {
-webkit-transition: all 0.3s ease;
-moz-transition: all 0.3s ease;
transition: all 0.3s ease;
}
/* Example media queries */
@media screen and (max-width: 55.1875em){
.cbp-spmenu-horizontal {
font-size: 75%;
height: 110px;
}
.cbp-spmenu-top {
top: -110px;
}
.cbp-spmenu-bottom {
bottom: -110px;
}
}
@media screen and (max-height: 26.375em){
.cbp-spmenu-vertical {
font-size: 90%;
width: 190px;
}
.cbp-spmenu-left,
.cbp-spmenu-push-toleft {
left: -190px;
}
.cbp-spmenu-right {
right: -190px;
}
.cbp-spmenu-push-toright {
left: 190px;
}
}
.nav-free-quote .button-orange {
width: 80%;
margin: 25px auto 0;
padding: 10px;
text-align: center;
}
.nav-free-quote .button-orange:hover {
background-color: #ffb22a;
}
.nav-free-quote .button-orange i {
color: #fff;
}
.sub-nav {
display: none;
}
/***** PHOTO HEAD *****
****************************************************************************/
.photo-head {
height:100%;
overflow-y:hidden;
background-image: url(../images/home-bg.jpg);
background-repeat: no-repeat;
background-attachment:fixed;
background-size:cover;
}
.photo-head2 {
height:100%;
overflow-y:hidden;
background-image: url(../images/home-bg3.jpg);
background-repeat: no-repeat;
background-attachment:fixed;
background-size:cover;
background-position: bottom;
height: 700px;
}
.photo-head3 {
height:100%;
overflow-y:hidden;
background-image: url(../images/home-bg3.jpg);
background-repeat: no-repeat;
background-attachment:fixed;
background-size:cover;
height: 700px;
}
.bg-overlay {
height:100%;
overflow-y:hidden;
background-color: rgba(28, 28, 28, 0.18);
background-repeat: no-repeat;
background-attachment:fixed;
background-size:cover;
}
.bg-overlay2 {
height:100%;
overflow-y:hidden;
background-color: rgba(28, 28, 28, 0.46);
background-repeat: no-repeat;
background-attachment:fixed;
background-size:cover;
}
.bg-overlay3 {
height:100%;
overflow-y:hidden;
background-color: rgba(28, 28, 28, 0.18);
background-repeat: no-repeat;
background-attachment:fixed;
background-size:cover;
}
.call-to-action {
display: block;
overflow: hidden;
margin: 150px auto 0;
text-align: right;
}
.call-to-action3 {
display: block;
overflow: hidden;
margin: 150px auto 0;
text-align: right;
}
.call-to-action-block {
display: block;
width: 52.5%;
float: right;
background-color: rgba(28, 28, 28, 0.6);
padding: 15px;
border-radius: 5px;
}
.call-to-action .cta-title {
font-family: 'Roboto Condensed', sans-serif;
font-weight: 600;
font-size: 68px;
color: #fff;
margin: 10px 0 15px 0;
padding: 0;
line-height: 55px;
}
.call-to-action3 .cta-title {
font-family: 'Roboto Condensed', sans-serif;
font-weight: 600;
font-size: 68px;
color: #fff;
margin: 10px 0 15px 0;
padding: 0;
line-height: 55px;
}
.call-to-action span {
display: block;
font-family: 'Roboto Condensed', sans-serif;
font-weight: 300;
font-size: 30px;
color: #fff;
margin: 0;
padding: 10px 0 0 0;
line-height: 35px;
}
.call-to-action3 span {
display: block;
font-family: 'Roboto Condensed', sans-serif;
font-weight: 300;
font-size: 30px;
color: #fff;
margin: 0;
padding: 10px 0 0 0;
line-height: 35px;
}
/***** INDEX *****
***************************************************************/
/** why eid **/
.why-eid {
display: block;
overflow: hidden;
padding: 50px 0;
}
.why-eid h1{
font-family: 'Roboto Condensed', sans-serif;
font-size: 80px;
font-weight: 300;
margin: 0 0 20px 0;
padding: 0;
line-height: 80px;
}
/** three **/
.pre-home-three {
padding: 50px 0;
background-color: #fff;
}
.feature,.project {
padding: 0 20px;
}
.feature i {
font-size: 70px;
color: #169CD0;
margin-bottom: 25px;
}
.feature i:hover {
transform: scale(1.2);
transition: all .2s ease;
}
.feature a, .project a {
font-size: 21px;
color: #4c5867;
font-weight: 400;
text-transform: uppercase;
}
.pre-home-lead-out{
padding: 100px 0;
background: linear-gradient(
rgba(0, 0, 0, 0.9),
rgba(0, 0, 0, 0.45)
),url(../images/home-lead-out-bg.jpg);
background-repeat: no-repeat;
background-attachment: fixed;
background-size: cover;
}
.home-lead-out-left {
}
.home-lead-out-left p {
text-align: left;
font-size: 26px;
color: #fff;
text-transform: uppercase;
margin: 0;
}
.home-lead-out-right {
margin: 15px 0 0 0;
}
.pre-recent-projects {
padding: 50px 0;
}
.project img {
margin: 0 0 5px 0;
}
.project h3 {
text-align: left;
margin: 0;
padding: 0;
}
.recent-projects h2 {
font-family: 'Roboto Condensed', sans-serif;
font-size: 38px;
font-weight: 300;
text-transform: uppercase;
margin: 0;
padding: 0;
}
/***** FOOTER *****
***************************************************************/
.pre-footer {
width: 100%;
background-color: #1A1A1A;
padding: 25px 0;
}
/*.sub-nav {
border-bottom: 1px solid #fff;
}*/
.footer ul li {
display: inline-block;
margin: 0 20px;
padding: 0;
}
.footer ul li a {
font-family: 'Roboto Condensed', sans-serif;
font-size: 16px;
font-weight: 300;
color: #888;
text-transform: uppercase;
}
.footer ul li a:hover {
color: #169CD0;
transition: all .75s ease;
}
.footer-logo {
padding: 8px 0;
}
.footer-logo img {
height: 50px;
width: 195px;
margin: 0 auto;
}
.foot-mail, .foot-phone {
display: inline;
margin: 0 10px
}
.foot-mail, .foot-phone {
font-family: 'Roboto Condensed', sans-serif;
font-weight: 300;
font-size: 20px;
color: #888;
}
.foot-mail a, .foot-phone a {
color: #888;
}
.foot-mail i, .foot-phone i {
font-weight: 900;
margin: 0 5px
}
.copyright p {
font-family: 'Roboto Condensed', sans-serif;
font-weight: 300;
font-size: 14px;
color: #888;
margin: 10px 0 0 0;
}
/****! responsive-nav.js 1.0.39 by @viljamis ****
***************************************************************/
.js .nav-collapse {
clip: rect(0 0 0 0);
max-height: 0;
position: fixed;
display: block;
overflow: hidden;
zoom: 1;
width: 100%;
}
.nav-collapse.opened {
max-height: 9999px;
}
@media screen and (min-width: 780px) {
.js .nav-collapse {
position: fixed;
z-index: 200;
}
.js .nav-collapse.closed {
max-height: none;
z-index: 200;
}
.nav-toggle {
display: none !important;
}
}

<body class="cbp-spmenu-push-toleft">
<?php include_once("analytics.php") ?>
<div class="pre-head">
<div class="grid-container head">
<div class="grid-100 mobile-grid-100" id="head_container">
<div class="compact fatnav_header" id="header">
<div id="header_logo">
<a href="index.html" class="logo_link"><img src="assets/images/logo.svg" title="Elegance in Design, Woodland CA." alt="Elegance In Design main logo" /></a>
</div>
<div id="fat_nav">
<nav class="cbp-spmenu cbp-spmenu-vertical cbp-spmenu-right cbp-spmenu-open" id="cbp-spmenu-s2">
<button id="close"><img src="assets/images/hamburger-white-close.svg" /></button>
<ul id="nav">
<li class="parent"><a class="nav-top" href="#">Web Design <i class="fa fa-angle-double-down"></i></a>
<ul class="sub-nav">
<li><a class="nav-top" href="self-storage-ws.html">Self Storage Websites</a></li>
<li><a class="nav-top" href="responsive-ws.html">Responsive Websites</a></li>
</ul>
</li>
<li class="parent"><a class="nav-top" href="#">Internet Marketing <i class="fa fa-angle-double-down"></i></a>
<ul class="sub-nav">
<li><a class="nav-top" href="seo.html">Real SEO</a></li>
<li><a class="nav-top" href="ppc.html">PPC (Pay Per Click) Ads</a></li>
<li><a class="nav-top" href="social-media-marketing.html">Social Media Marketing</a></li>
</ul>
</li>
<li class="parent"><a class="nav-top" href="hosting.html">Website Hosting</a></li>
<li class="parent"><a class="nav-top" href="#">About Us <i class="fa fa-angle-double-down"></i></a>
<ul class="sub-nav">
<li><a class="nav-top" href="about.html">About EiD</a></li>
<li><a class="nav-top" href="careers.html">Careers</a></li>
</ul>
</li>
<li class="parent"><a class="nav-top" href="contact.html">Contact Us</a></li>
</ul>
<div class="nav-free-quote">
<a class="button-orange" href="free-quote.html"><i class="fa fa-angle-double-right"></i> Free Quote</a>
</div>
</nav>
<button id="showRightPush"><img src="assets/images/hamburger-white-open.svg" /></button>
</div><!-- END OF FAT NAV -->
</div><!-- END OF HEADER -->
</div><!-- END OF HEAD CONTAINER -->
</div><!-- END OF HEAD -->
</div><!-- END OF PRE HEAD -->
<div class="photo-head2">
<div class="bg-overlay2">
<div class="grid-container">
<div class="grid-100 mobile-grid-100 call-to-action">
<!--<div class="call-to-action-block">-->
<span class="cta-title">Best Your Competition!<br>
<span>OUR SPECIALTY: helping local businesses market<br/> and advertise online EFFECTIVELY.</span></span>
<a class="button" href="internet-marketing.html"><i class="fa fa-angle-double-right"></i> Check out our services</a>
<!--</div>-->
</div>
</div>
</div>
</div><!-- END OF PHOTO HEAD -->
<!-- SCRIPTS -->
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js"></script>
<script src="./assets/javascripts/scripts.js"></script>
</body>
&#13;