gpt4 book ai didi

jquery - 如何做侧滑子菜单?

转载 作者:行者123 更新时间:2023-11-28 17:13:40 24 4
gpt4 key购买 nike

我管理了一个带有菜单按钮的垂直滑动侧边菜单。当我点击它时,一个菜单从左边出现/消失。当我单击具有子菜单的菜单项时,我想达到相同的效果。我做了很多尝试,但还没有运气。我感谢有关如何修改或添加到我的代码的任何建议。(我知道我必须添加一些过渡......)

很明显我是新手。提前致谢,最好!

HTML代码:

<!DOCTYPE html>
<html lang="sp" >
<head>
<meta charset="UTF-8" />
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Menúes</title>

<link rel="stylesheet" type="text/css" href="css/menup.css" />

<script src="js/jquery203.js"></script>

<script src="js/menup.js"></script>

</head>
<body>
<!-- Navigation -->
<div class="container">
<div id="sidebar">
<ul class="menu">
<li class="parent"><a href="#" class="home">Home ></a></li>
<ul class="submenu">
<li><a href="#" class="home">Home 11</a></li>
<li><a href="#" class="users">Home 12</a></li>
<li><a href="#" class="signout">Home 13</a></li>
</ul>
<li><a href="#" class="explore">Explore</a></li>
<li><a href="#" class="users"> Users</a></li>
<li><a href="#" class="signout"> Sign Out</a></li>
</ul>
</div>
<div class="main-content">
<a href="#" data-toggle=".container" id="sidebar-toggle">
<span class="bar"></span>
<span class="bar"></span>
<span class="bar"></span>
</a>
<div class="content">
</div>
</div>
</div>
</body>
</html>

CSS3代码:

body, html {
height: 100%;
margin: 0;
overflow:hidden;
font-family: helvetica;
font-weight: 100;
}
.container {
position: relative;
height: 100%;
width: 100%;
right: 0;
-webkit-transition: right 0.4s ease-in-out;
-moz-transition: right 0.4s ease-in-out;
-ms-transition: right 0.4s ease-in-out;
-o-transition: right 0.4s ease-in-out;
transition: right 0.4s ease-in-out;

}

.container.open-sidebar {
right: 240px;
}


#sidebar {
position: absolute;
right: -240px;
background: #DF314D;
width: 240px;
height: 100%;
box-sizing: border-box;
-moz-box-sizing: border-box;
border-radius: 4px;

}

#sidebar ul {
margin: 0;
padding: 0;
list-style: none;
}


#sidebar ul li {
margin: 0;

}
#sidebar ul li a {

padding: 15px 20px 15px 35px;
font-size: 16px;
font-weight: 100;
color: white;
text-decoration: none;
display: block;
border-bottom: 1px solid #C9223D;

-webkit-transition: background 0.3s ease-in-out;
-moz-transition: background 0.3s ease-in-out;
-ms-transition: background 0.3s ease-in-out;
-o-transition: background 0.3s ease-in-out;
transition: background 0.3s ease-in-out;
}


#sidebar li:hover {

background: #C9223D;
border-radius: 4px;
}


.main-content {
width: 100%;
height: 100%;
padding: 10px;
box-sizing: border-box;
-moz-box-sizing: border-box;
position: relative;
}

.main-content .content{
box-sizing: border-box;
-moz-box-sizing: border-box;
padding-left: 60px;
width: 100%;
}
.main-content .content h1{
font-weight: 100;
}
.main-content .content p{
width: 100%;
line-height: 160%;
}
.main-content #sidebar-toggle {
background: #DF314D;
border-radius: 3px;
display: block;
position: relative;
padding: 10px 7px;
float: right;
}
.main-content #sidebar-toggle .bar{
display: block;
width: 18px;
margin-bottom: 3px;
height: 2px;
background-color: #fff;
border-radius: 1px;
}
.main-content #sidebar-toggle .bar:last-child{
margin-bottom: 0;
}

.main-content #sidebar-toggle .bar{
display: block;
width: 18px;
margin-bottom: 3px;
height: 2px;
background-color: #fff;
border-radius: 1px;
}

.main-content #sidebar-toggle .bar:last-child{
margin-bottom: 0;
}


.menu a.home {

display: inline-block;
background: url(../imagenes/bpi.png) no-repeat 4px 10px;


}

.menu a.explore {

display: inline-block;
background: url(../imagenes/gasi.png) no-repeat 4px 10px;
}

.menu a.users {

display: inline-block;
background: url(../imagenes/bicici.png) no-repeat 4px 10px;
}

.menu a.signout {

display: inline-block;
background: url(../imagenes/bai.png) no-repeat 4px 10px;
}


#sidebar .menu .submenu {
display: none;

}


#sidebar ul li ul.visible{
display: block;
}

.submenu a.home {

display: inline-block;
background: url(../imagenes/bpi.png) no-repeat 4px 10px;
}



.submenu a.users {

display: inline-block;
background: url(../imagenes/bicici.png) no-repeat 4px 10px;
}

.submenu a.signout {

display: inline-block;
background: url(../imagenes/bai.png) no-repeat 4px 10px;
}

JS代码,它不以任何方式显示子菜单。

$(document).ready(function() {
$("[data-toggle]").click(function() {
var toggle_el = $(this).data("toggle");
$(toggle_el).toggleClass("open-sidebar");
});
$('parent').click(function() {
$('.submenu').toggleClass('visible');
});

});

最佳答案

使用这个你忘了放标识符.parent检查下面的代码你只是使用toggle作为子菜单

$(document).ready(function() {
$("[data-toggle]").click(function() {
var toggle_el = $(this).data("toggle");
$(toggle_el).toggleClass("open-sidebar");
});
$('.parent').click(function() {
$('.submenu').toggle('visible');
});

});

Check Demo Here

关于jquery - 如何做侧滑子菜单?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28893575/

24 4 0
文章推荐: jquery - 如果没有空间可填充,如何使
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com