作者:嗯哼 | 来源:互联网 | 2023-06-09 10:58
WhenItoggleopenmySlide-Leftmenuandselectananchortaglink,itnaviagtestotheanchoredse
When I toggle open my Slide-Left menu and select an anchor tag link, it naviagtes to the anchored section on the same page, but the menu remains open.
当我切换打开我的Slide-Left菜单并选择一个锚标记链接时,它会导航到同一页面上的锚定部分,但菜单仍保持打开状态。
I would like a simple Javascript function to close the toggle menu everytime I click on an achor link and navigate to the desire section
每当我点击achor链接并导航到欲望部分时,我想要一个简单的Javascript函数来关闭切换菜单
https://jsfiddle.net/trsjL9th/
I've tried all the other solutions I found on stack overflow including:
我已经尝试了我在堆栈溢出时发现的所有其他解决方案,包括:
$('#menu li').on('click', function(){ $("#menu").hide(); $("#menu-icon").removeClass("active"); });
$('#menin li')。on('click',function(){$(“#menu”)。hide(); $(“#menu-icon”)。removeClass(“active”);}) ;
But nothing seems to be working, I'm still really new at Javascript so any help or push in the right direction will be greatly appreciated.
但似乎没有任何工作,我仍然是Javascript的新手,所以任何帮助或推动正确的方向将不胜感激。
Javascript:
(function(window) {
'use strict';
/**
* Extend Object helper function.
*/
function extend(a, b) {
for(var key in b) {
if(b.hasOwnProperty(key)) {
a[key] = b[key];
}
}
return a;
}
/**
* Each helper function.
*/
function each(collection, callback) {
for (var i = 0; i
HTML:
CSS:
.c-menu {
position: fixed;
z-index: 200;
background-color: #333;
transition: transform 0.3s;
}
.c-menu__items {
list-style: none;
margin: 0;
padding: 0; margin-top:90px;
}
.c-menu__items li {
font-size:20px; margin-top:20px;
}
/**
* Close button resets.
*/
.c-menu__close {
color: #fff;
background-color:#333;
font-size: 14px;
border: none;
box-shadow: none;
border-radius: none;
-webkit-appearance: none;
-moz-appearance: none;
appearance: none;
cursor: pointer;
}
/**
* Close button resets.
*/
.c-menu__close:focus {
outline: none;
}
/**
* Body states.
*
* When a menu is active, we want to hide the overflows on the body to prevent
* awkward document scrolling.
*/
body.has-active-menu {
overflow: hidden;
}
.c-button {
background-color: blue;
background-repeat: no-repeat;
background-position: 0px 0px;
border: none; margin-top:13px; margin-left:5px;
cursor: pointer; z-index:1;
height: 25px;
padding-left: 25px;
vertical-align: middle;
}
.c-menu__close {
background-color: white;
background-repeat: no-repeat;
background-position: 0px 0px;
border: none; margin-top:10px; margin-right:2px;
cursor: pointer;
height: 25px;
padding-left: 25px;
vertical-align: middle;
}
.c-mask {
position: fixed;
z-index: 100;
top: 0;
left: 0;
overflow: hidden;
width: 0;
height: 0;
background-color: #000;
opacity: 0;
transition: opacity 0.3s, width 0s 0.3s, height 0s 0.3s;
}
.c-mask.is-active {
width: 100%;
height: 100%;
opacity: 0.7;
transition: opacity 0.3s;
}
.c-menu--slide-left,
.c-menu--slide-right,
.c-menu--push-left,
.c-menu--push-right {
width: 100%;
height: 100%;
overflow-y: auto;
}
@media all and (min-width: 320px) {
.c-menu--slide-left,
.c-menu--slide-right,
.c-menu--push-left,
.c-menu--push-right {
width: 300px;
}
}
.c-menu--slide-left .c-menu__item,
.c-menu--slide-right .c-menu__item,
.c-menu--push-left .c-menu__item,
.c-menu--push-right .c-menu__item {
display: block;
text-align: left;
}
.c-menu--slide-left .c-menu__item:first-child,
.c-menu--slide-right .c-menu__item:first-child,
.c-menu--push-left .c-menu__item:first-child,
.c-menu--push-right .c-menu__item:first-child {
border-top: none;
}
.c-menu--slide-left .c-menu__item:last-child,
.c-menu--slide-right .c-menu__item:last-child,
.c-menu--push-left .c-menu__item:last-child,
.c-menu--push-right .c-menu__item:last-child {
border-bottom: none;
}
.c-menu--slide-left .c-menu__link,
.c-menu--slide-right .c-menu__link,
.c-menu--push-left .c-menu__link,
.c-menu--push-right .c-menu__link {
display: block; text-decoration:none; margin-top:15px;
padding: 4px 24px;
color: #fff;
}
.c-menu__link:hover {color:#c8d100;}
.c-menu--slide-left .c-menu__close,
.c-menu--slide-right .c-menu__close,
.c-menu--push-left .c-menu__close,
.c-menu--push-right .c-menu__close {
display: block;
padding: 10px 10px; clear:both;
width: 30px;float:right;
}
.c-menu--slide-left,
.c-menu--push-left {
top: 0;
left: 0;
transform: translateX(-100%);
}
@media all and (min-width: 320px) {
.c-menu--slide-left,
.c-menu--push-left {
transform: translateX(-300px);
}
}
.c-menu--slide-left.is-active,
.c-menu--push-left.is-active {
transform: translateX(0);
}
.c-menu--slide-right,
.c-menu--push-right {
top: 0;
right: 0;
transform: translateX(100%);
}
@media all and (min-width: 320px) {
.c-menu--slide-right,
.c-menu--push-right {
transform: translateX(300px);
}
}
.c-menu--slide-right.is-active,
.c-menu--push-right.is-active {
transform: translateX(0);
}
.o-wrapper.has-push-left {
transform: translateX(100%);
}
@media all and (min-width: 320px) {
.o-wrapper.has-push-left {
transform: translateX(300px);
}
}
.o-wrapper.has-push-right {
transform: translateX(-100%);
}
@media all and (min-width: 320px) {
.o-wrapper.has-push-right {
transform: translateX(-300px);
}
}
#about { background:blue; height:100vh; width:100%; color:white; font-size:100px;}
#contact { background:yellow; height:100vh; width:100%; color:white; font-size:100px;}
#howitworks { background:green; height:100vh; width:100%; color:white; font-size:100px;}
#tools { background:red; height:100vh; width:100%; color:white; font-size:100px;}
#about { background:black; height:100vh; width:100%; color:white; font-size:100px;}
#help { background:green; height:100vh; width:100%; color:white; font-size:100px;}
#customers { background:purple; height:100vh; width:100%; color:white; font-size:100px;}
#business { background:orange; height:100vh; width:100%; color:white; font-size:100px;}
#location { background:brown; height:100vh; width:100%; color:white; font-size:100px;}
2 个解决方案