演示 - https://jsfiddle.net/jhhpLapv/1/
// Main Script For Ciel Viole
$(document).ready(function() {
$('.client-link').click(function() {
$('.navbar').slideToggle("fast");
});
});
当触发汉堡菜单时,我希望菜单链接到淡入淡出,然后在菜单关闭时逐渐淡出。我对此非常陌生,就我所知。如何在第一次单击菜单时听取事件触发淡入淡出,并在第二次单击时淡出淡出?
答案 0 :(得分:1)
这是您可以尝试的一种方式。 Working Fiddle
我刚刚用以下代码更新了代码:
$(document).ready(function() {
var $navbar = $('.navbar');
$('.client-link').click(function() {
if (!$navbar.hasClass("active")) {
$navbar.fadeIn("slow").addClass("active");
}
else {
$navbar.fadeOut("slow").removeClass("active");
}
});
});
答案 1 :(得分:0)
应该工作:
$(document).ready(function() {
$('.client-link').click(function() {
if($('.navbar').is(':visible')){
$('.navbar').fadeOut("fast");
}else{
$('.navbar').fadeIn("fast");
}
});
});
答案 2 :(得分:0)
始终尝试基于CSS的动画。它们非常流畅且易于实现。
这是怎么回事。而不是调用fadeIn()
和fadeOut()
只需向目标元素添加一个类。然后在css中,您可以使用transition: all 0.3s ease-in;
(或任何其他更好的值)来创建转换。以下是使用您的代码的示例。你可以做到这一点,比这更好。
// Main Script For Ciel Viole
$(document).ready(function() {
$('.client-link').click(function() {
$('.navbar').toggleClass("active");
});
});

.client-item {
position: relative;
float: right;
list-style: none;
}
.client-link {
font-size: 2rem;
font-weight: 600;
text-decoration: none;
text-transform: uppercase;
color: #c5c5c5;
}
.client-link:hover {
color: #151515;
-webkit-transition: color 2s ease;
transition: color 2s ease;
}
.navbar {
display: none;
-webkit-animation-delay: .3s;
animation-delay: .3s;
}
.about-header {
font-size: 3rem;
line-height: 34px;
font-weight: 600;
margin-top: 2rem;
}
.values {
background-image: url('../images/infinity-bg.jpg');
background-size: contain;
color: #fff;
padding-bottom: 15rem;
margin-top: 2rem;
}
.title {
font-size: 1.8rem;
font-family: 'Libre Baskerville', serif;
font-weight: 400;
letter-spacing: .4rem;
-webkit-font-smoothing: antialiased;
text-rendering: optimizeLegibility;
}
.title a {
color: #767676;
}
.content-section {
padding: 1rem 0;
margin-bottom: 2.5rem;
}
.navbar-list {
list-style: none;
margin-bottom: 0;
display: inline-flex;
}
.navbar-item {
position: relative;
float: left;
margin-bottom: 0;
}
.navbar-link {
font-size: 1.2rem;
letter-spacing: .2rem;
font-weight: 600;
margin: 0 25px 0 0;
text-transform: uppercase;
line-height: 6.5rem;
color: #7c7c7c;
font-family: 'Arimo', sans-serif !important;
-webkit-font-smoothing: antialiased;
text-rendering: optimizeLegibility;
}
.navbar-link:hover {
color: #000000;
-webkit-transition: color 2s ease;
transition: color 2s ease;
}
.navbar-link-left {
font-size: 1.2rem;
letter-spacing: .2rem;
font-weight: 600;
margin: 0 0 0 25px;
text-transform: uppercase;
line-height: 6.5rem;
color: #7c7c7c;
font-family: 'Arimo', sans-serif !important;
-webkit-font-smoothing: antialiased;
text-rendering: optimizeLegibility;
}
.navbar-link-left:hover {
color: #000000;
-webkit-transition: color 2s ease;
transition: color 2s ease;
}
/* Roy's override */
.navbar {
display: block;
width: 0px;
overflow: hidden;
-webkit-transition: all .3s ease;
transition: all .3s ease;
float: right;
background: #f1f1f1;
}
.navbar.active {
width: 100%;
}
.navbar-item {
opacity: 0;
-webkit-transition: all .3s ease;
transition: all .3s ease;
-webkit-transition-delay: .3s;
transition-delay: .3s;
}
.navbar.active .navbar-item {
opacity: 1;
}

<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<link href="https://maxcdn.bootstrapcdn.com/font-awesome/4.5.0/css/font-awesome.min.css" rel="stylesheet" />
<section class="header">
<h2 class="title"><a href="#">Site Title</a>
<li class="client-item"><a class="client-link" href="#"><i class="fa fa-bars"></i></a></li></h2>
</section>
<nav class="navbar">
<ul class="navbar-list">
<li class="navbar-item"><a class="navbar-link-left" href="#" target="_top">Contact</a>
</li>
<li class="navbar-item"><a class="navbar-link-left" href="#" target="_top">Store</a>
</li>
</ul>
<ul class="navbar-list Right">
<li class="navbar-item"><a class="navbar-link" href="" target="_blank"><i class="fa fa-youtube"></i></a>
</li>
<li class="navbar-item"><a class="navbar-link" href="" target="_blank"><i class="fa fa-soundcloud"></i></a>
</li>
<li class="navbar-item"><a class="navbar-link" href="" target="_blank"><i class="fa fa-twitter"></i></a>
</li>
<li class="navbar-item"><a class="navbar-link" href="/" target="_blank"><i class="fa fa-instagram"></i></a>
</li>
<li class="navbar-item"><a class="navbar-link" href="" target="_blank"><i class="fa fa-facebook"></i></a>
</li>
<li class="navbar-item"><a class="navbar-link" href="#" target="_blank"><i class="fa fa-apple"></i></a>
</li>
</ul>
</nav>
&#13;