gpt4 book ai didi

javascript - Bourbon Refill Navigation Menu 在点击时向上滑动

转载 作者:数据小太阳 更新时间:2023-10-29 04:49:32 24 4
gpt4 key购买 nike

我正在使用 Bourbon Refill 导航菜单,我想对其进行修改,以便当在小模式下单击链接时,菜单会向上滑动。目前菜单会下拉,但是当单击菜单项时,菜单会保持下拉状态。由于我使用带有固定顶部菜单的页面滚动,这意味着很多内容隐藏在菜单后面。

这是Codepen上的代码:

http://codepen.io/mikehdesign/pen/LVjbPv/

我现有的代码如下:

HTML

<header class="navigation" role="banner">
<div class="navigation-wrapper">
<a href="javascript:void(0)" class="logo">
<img src="https://raw.githubusercontent.com/thoughtbot/refills/master/source/images/placeholder_logo_1_dark.png" alt="Logo Image">
</a>
<a href="javascript:void(0)" class="navigation-menu-button" id="js-mobile-menu">Menu</a>
<nav role="navigation">
<ul id="js-navigation-menu" class="navigation-menu show">
<li class="nav-link"><a href="javascript:void(0)">About Us</a></li>
<li class="nav-link"><a href="javascript:void(0)">Contact</a></li>
<li class="nav-link"><a href="javascript:void(0)">Testimonials</a></li>
<li class="nav-link"><a href="javascript:void(0)">Sign up</a></li>
</ul>
</nav>

SCSS

.navigation {
$large-screen: em(860) !default;
$large-screen: $large-screen;

// Mobile view
.navigation-menu-button {
display: block;
float: right;
margin: 0;
padding-top: 0.5em;

@include media ($large-screen) {
display: none;
}
}

// Nav menu
.navigation-wrapper {
@include clearfix;
position: relative;
}

.logo {
float: left;

img {
max-height: 2em;
padding-right: 1em;
}
}

nav {
float: none;

@include media ($large-screen) {
float: left;
line-height: 1.5em;
padding-top: 0.3em;
}
}

ul.navigation-menu {
clear: both;
display: none;
margin: 0 auto;
overflow: visible;
padding: 0;
width: 100%;

@include media ($large-screen) {
display: block;
margin: 0;
padding: 0;
}

&.show {
display: block;
}
}

// Nav items
ul li.nav-link {
display: block;
text-align: right;
width: 100%;

@include media ($large-screen) {
background: transparent;
display: inline;
text-decoration: none;
width: auto;
}
}

li.nav-link a {
display: inline-block;

@include media ($large-screen) {
padding-right: 1em;
}
}
}

JS

$(document).ready(function() {
var menuToggle = $('#js-mobile-menu').unbind();
$('#js-navigation-menu').removeClass("show");

menuToggle.on('click', function(e) {
e.preventDefault();
$('#js-navigation-menu').slideToggle(function(){
if($('#js-navigation-menu').is(':hidden')) {
$('#js-navigation-menu').removeAttr('style');
}
});
});
});

非常感谢帮助

迈克

最佳答案

按照您的预期查看以下经过测试的小版本和大版本的演示。

编辑 2

根据您的要求更新了小版本的切换。

Codepen

jQuery

function smallVersion() {
$("#js-navigation-menu a").on('click', function(e) {
$('#js-navigation-menu').slideToggle(function() {
if ($('#js-navigation-menu').is(':hidden')) {
$('#js-navigation-menu').removeAttr('style');
}
});
});
}

function dothis(){
var ww = $(window).width();
var emToPx = 53.75 * parseFloat($("html").css("font-size"));
if( ww < emToPx ) {
smallVersion();
}
}

$(document).ready(function() {
var menuToggle = $('#js-mobile-menu').unbind();
$('#js-navigation-menu').removeClass("show");

menuToggle.on('click', function(e) {
e.preventDefault();
$('#js-navigation-menu').slideToggle(function(){
if($('#js-navigation-menu').is(':hidden')) {
$('#js-navigation-menu').removeAttr('style');
}
});
});

dothis();
});

关于javascript - Bourbon Refill Navigation Menu 在点击时向上滑动,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29035883/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com