gpt4 book ai didi

jquery - 带有子菜单的菜单。个人电脑、平板电脑和手机

转载 作者:行者123 更新时间:2023-11-28 05:37:48 25 4
gpt4 key购买 nike

这是一个带有子菜单的菜单代码,不工作子菜单。菜单代码适用于个人电脑和平板电脑,但子菜单不起作用。另外,我希望子菜单在平板电脑中像 Accordion 一样工作。

$(document).ready(main);

var contador = 1;

function main (){
$('.menu_bar').click(function(){
// $('nav').toggle(); Forma Sencilla de aparecer y desaparecer

if (contador == 1){
$('nav').animate({
left: '0'
});
contador = 0;
} else {
contador = 1;
$('nav').animate({
left: '-100%'
});
};

});
};
/* CSS Document */
@font-face {
font-family: 'FalconMasters';
src:url('../fonts/FalconMasters.eot?-ibh2ms');
src:url('../fonts/FalconMasters.eot?#iefix-ibh2ms') format('embedded-opentype'),
url('../fonts/FalconMasters.woff?-ibh2ms') format('woff'),
url('../fonts/FalconMasters.ttf?-ibh2ms') format('truetype'),
url('../fonts/FalconMasters.svg?-ibh2ms#FalconMasters') format('svg');
font-weight: normal;
font-style: normal;
}

[class^="icon-"], [class*=" icon-"] {
font-family: 'FalconMasters';
speak: none;
font-style: normal;
font-weight: normal;
font-variant: normal;
text-transform: none;
line-height: 1;

/* Better Font Rendering =========== */
-webkit-font-smoothing: antialiased;
-moz-osx-font-smoothing: grayscale;
}

.icon-mail:before {
content: "\e604";
}
.icon-house:before {
content: "\e622";
}
.icon-rocket:before {
content: "\e650";
}
.icon-suitcase:before {
content: "\e652";
}
.icon-earth:before {
content: "\e654";
}
.icon-cross:before {
content: "\e678";
}
.icon-list2:before {
content: "\e696";
}



* {
margin:0;
padding:0;
}

body {
background:#FFFFFA;
}

header {
width:100%;
}

header nav {
width:100%;
max-width:1000px;
background:#024959;
}

.menu_bar {
display:none;
}

nav ul {
overflow:hidden;
list-style:none;
}

nav ul li {
float:left;
position:relative;
display:inline-block;
}

nav ul li a {
color:#fff;
padding:20px;
display:block;
text-decoration:none;
line-height:20px;
position: relative;
-webkit-transition: all .3s ease;
-moz-transition: all .3s ease;
-ms-transition: all .3s ease;
-o-transition: all .3s ease;
transition: all .3s ease;
}

nav ul li span {
margin-right:10px;
}

nav ul li a:hover {
background:#037E8C;
}

section {
padding:20px;
}

/*Sub-menu*/
nav .submenu1{
position:relative;
display: none;
width: 100%;
margin: 0;
padding: 0;
}

#submenu a:hover .submenu1{
display: block;
background-color:#D90B0F;
}

@media screen and (max-width:800px ) {
header nav {
width:80%;
height:100%;
left:-100%;
margin:0;
position: fixed;
}

header nav ul li {
display:block;
float:none;
border-bottom:1px solid rgba(255,255,255, .3);
}

.menu_bar {
display:block;
width:100%;
background:#ccc;
}

.menu_bar .bt-menu {
display:block;
padding:20px;
background:#024959;
color:#fff;
text-decoration:none;
font-weight: bold;
font-size:25px;
-webkit-box-sizing:border-box;
-moz-box-sizing:border-box;
box-sizing:border-box;
}

.menu_bar span {
float:right;
font-size:40px;
}
}
<!doctype html>
<html>
<head>
<meta name="viewport" content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0">
<link rel="stylesheet" href="http://i.icomoon.io/public/temp/7d96e2500b/UntitledProject7/style.css">
<link rel="stylesheet" href="assets/css/menuH.css">

<title>index</title>

<meta charset="utf-8">

</head>

<body>
<header>
<div class="menu_bar">
<a href="#" class="bt-menu"><span class="icon-list2"></span>Menu</a>
</div>

<nav>
<ul>
<li><a href="#"><span class="icon-house"></span>Inicio</a></li>
<li id="submenu"><a href="#"><span class="icon-suitcase"></span>Trabajos</a>
<ul class="submenu1">
<li><a href="#">Item #1</a></li>
<li><a href="#">Item #2</a></li>
<li><a href="#">Item #3</a></li>
<li><a href="#">Item #4</a></li>
<li><a href="#">Item #5</a></li>
</ul>

</li>

<li><a href="#"><span class="icon-rocket"></span>Proyectos</a></li>
<li><a href="#"><span class="icon-earth"></span>Servicios</a></li>
<li id="submenu"><a href="#"><span class="icon-mail"></span>Contactos</a></li>
</ul>
</nav>
</header>
<script src="http://code.jquery.com/jquery-latest.js"></script>

</body>
</html>

#submenu a:hover .submenu1{
display: block;
background-color:#D90B0F;
}

为什么?

---------------- CSS 3 --------------

/* CSS Document */
@font-face {
font-family: 'FalconMasters';
src:url('../fonts/FalconMasters.eot?-ibh2ms');
src:url('../fonts/FalconMasters.eot?#iefix-ibh2ms') format('embedded-opentype'),
url('../fonts/FalconMasters.woff?-ibh2ms') format('woff'),
url('../fonts/FalconMasters.ttf?-ibh2ms') format('truetype'),
url('../fonts/FalconMasters.svg?-ibh2ms#FalconMasters') format('svg');
font-weight: normal;
font-style: normal;
}

[class^="icon-"], [class*=" icon-"] {
font-family: 'FalconMasters';
speak: none;
font-style: normal;
font-weight: normal;
font-variant: normal;
text-transform: none;
line-height: 1;

/* Better Font Rendering =========== */
-webkit-font-smoothing: antialiased;
-moz-osx-font-smoothing: grayscale;
}

.icon-mail:before {
content: "\e604";
}
.icon-house:before {
content: "\e622";
}
.icon-rocket:before {
content: "\e650";
}
.icon-suitcase:before {
content: "\e652";
}
.icon-earth:before {
content: "\e654";
}
.icon-cross:before {
content: "\e678";
}
.icon-list2:before {
content: "\e696";
}



* {
margin:0;
padding:0;
}

body {
background:#FFFFFA;
}

header {
width:100%;
}

header nav {
width:100%;
max-width:1000px;
background:#024959;
}

.menu_bar {
display:none;
}

nav ul {
overflow:hidden;
list-style:none;
}

nav ul li {
float:left;
position:relative;
display:inline-block;
}

nav ul li a {
color:#fff;
padding:20px;
display:block;
text-decoration:none;
line-height:20px;
position: relative;
-webkit-transition: all .3s ease;
-moz-transition: all .3s ease;
-ms-transition: all .3s ease;
-o-transition: all .3s ease;
transition: all .3s ease;
}

nav ul li span {
margin-right:10px;
}

nav ul li a:hover {
background:#037E8C;
}

section {
padding:20px;
}

/*Sub-menu*/
nav .submenu1{
position:relative;
display: none;
width: 100%;
margin: 0;
padding: 0;
}

#submenu a:hover .submenu1{
display: block;
background-color:#D90B0F;
}

@media screen and (max-width:800px ) {
header nav {
width:80%;
height:100%;
left:-100%;
margin:0;
position: fixed;
}

header nav ul li {
display:block;
float:none;
border-bottom:1px solid rgba(255,255,255, .3);
}

.menu_bar {
display:block;
width:100%;
background:#ccc;
}

.menu_bar .bt-menu {
display:block;
padding:20px;
background:#024959;
color:#fff;
text-decoration:none;
font-weight: bold;
font-size:25px;
-webkit-box-sizing:border-box;
-moz-box-sizing:border-box;
box-sizing:border-box;
}

.menu_bar span {
float:right;
font-size:40px;
}
}

-------------------- html5 ----------------

<!doctype html>
<html>
<head>
<meta name="viewport" content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0">
<link rel="stylesheet" href="http://i.icomoon.io/public/temp/7d96e2500b/UntitledProject7/style.css">
<link rel="stylesheet" href="assets/css/menuH.css">

<title>index</title>

<meta charset="utf-8">

</head>

<body>
<header>
<div class="menu_bar">
<a href="#" class="bt-menu"><span class="icon-list2"></span>Menu</a>
</div>

<nav>
<ul>
<li><a href="#"><span class="icon-house"></span>Inicio</a></li>
<li id="submenu"><a href="#"><span class="icon-suitcase"></span>Trabajos</a></li>
<ul class="submenu1">
<li><a href="#">Item #1</a></li>
<li><a href="#">Item #2</a></li>
<li><a href="#">Item #3</a></li>
<li><a href="#">Item #4</a></li>
<li><a href="#">Item #5</a></li>
</ul>
<li><a href="#"><span class="icon-rocket"></span>Proyectos</a></li>
<li><a href="#"><span class="icon-earth"></span>Servicios</a></li>
<li id="submenu"><a href="#"><span class="icon-mail"></span>Contactos</a></li>
</ul>
</nav>
</header>
<script src="http://code.jquery.com/jquery-latest.js"></script>
<script>
$(document).ready(main);

var contador = 1;

function main (){
$('.menu_bar').click(function(){
// $('nav').toggle(); Forma Sencilla de aparecer y desaparecer

if (contador == 1){
$('nav').animate({
left: '0'
});
contador = 0;
} else {
contador = 1;
$('nav').animate({
left: '-100%'
});
};

});
};
</script>
</body>
</html>

谢谢。

最佳答案

您可以添加一个新类以在您的菜单中使用“toggleClass”。像这样:

.show_menu_bar {
left:0;
}

并为动画添加到导航的过渡:

header nav {
width:100%;
max-width:1000px;
background:#024959;
transition: all ease .4s;
position: relative;
}

我建议您在 jQuery 上使用方法“on”。您可以阅读它的工作原理 here .

$(document).on('click', '.menu_bar', function() {
$('nav').toggleClass('show_menu_bar');
});

要使子菜单具有动画效果,请向主菜单按钮添加一个类并再次使用“on()”

$(document).on('click', '.display_submenu', function() {
$(this).next().slideToggle('fast');
});

子菜单的 CSS:

nav .display_submenu + * {
position: absolute !important;
top:100%;
background: #024959;
}
@media screen and (max-width:800px ) {
nav .display_submenu + * {
position: relative !important;
top:auto;
background: inherit;
}
}

您可以看到此示例有效 here .来自墨西哥的问候

关于jquery - 带有子菜单的菜单。个人电脑、平板电脑和手机,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38088144/

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