尝试做一个非常简单的 jQuery 动画...
nav 元素将以负边距进行动画处理,但未应用 .nav_btn2 类,因此 nav 元素不会动画回原始边距。在这里待了几个小时,实际上整晚都在……早上 7 点 47 分,我还没睡,等等。
jQuery v1.7.1
<script type="text/javascript">
$(document).ready(function() {
$('.nav_btn').on('click',function() {
$('nav').animate({marginLeft: '-445'}, 500);
$('.nav_btn').removeClass('nav_btn').addClass('nav_btn2');
});
$('.nav_btn2').on('click',function() {
$('nav').animate({marginLeft: '445'}, 500);
$('.nav_btn2').removeClass('nav_btn2').addClass('nav_btn');
});
});
</script>
HTML
<nav>
<img src="" alt="Detour Bar" id="logo" />
<ul>
<li><a href="#" class="nav_btn">BLOG</a></li>
<li><a href="#" class="nav_btn">PHOTOS</a></li>
<li><a href="#" class="nav_btn">CALANDER</a></li>
<li><a href="info.php" class="nav_btn">INFO</a></li>
</ul>
<div id="menu_btn" class="nav_btn">
</div>
</nav>
CSS
nav {
height: 100%;
width: 425px;
padding: 20px 0px 0px 20px;
background: rgb(255,255,255);
background: rgba(255,255,255,.5);
border-right: 7px solid #000;
position: fixed;
top: 0px;
left: 0px;
}
nav ul {
padding: 40px 0px 0px 0px;
list-style: none;
}
nav li {
padding: 0px 55px 0px 0px;
text-align: right;
}
nav a {
font-size: 4em;
color: #000;
}
#menu_btn {
width: 40px;
height: 161px;
border: 10px solid #000;
border-top: 15px solid #000;
border-bottom: 20px solid #000;
border-top-right-radius: 10px;
border-bottom-right-radius: 10px;
background: rgb(0,0,0);
background-image: url(img/menu.png);
background-repeat: no-repeat;
position: absolute;
top: 40px;
right: -60px;
}
Jquery v1.7.1 工作...感谢@micha
<script type="text/javascript">
$(document).ready(function() {
$(document).on('click','.nav_btn',function() {
$('nav').animate({marginLeft: '-445'}, 500);
$('.nav_btn').removeClass('nav_btn').addClass('nav_btn2');
});
$(document).on('click','.nav_btn2',function() {
$('nav').animate({marginLeft: '0'}, 500);
$('.nav_btn2').removeClass('nav_btn2').addClass('nav_btn');
});
});
</script>
任何建议将不胜感激!!!