【发布时间】:2014-09-22 18:59:26
【问题描述】:
我正在尝试获得一个简单的侧导航栏,您可以通过一个按钮来隐藏和取消隐藏它。
到目前为止,我有它worknig,但只有每隔一次点击,所以点击隐藏作品,然后什么都不做,下一次点击取消隐藏,什么都没有等等。但我必须将按钮设置为图像才能更改在每次点击时,这是有效的。
到目前为止我所拥有的是......
HTML:
<div id="navBar-control">
<a href="#" id="toggle-slide-button">
<img src="http://i.imgur.com/8BMxPsC.png" width="50px" height="50px" />
</a>
</div>
<div id="navBar">
<div class="navBtn navBtnText">
Calculator
</div>
<div class="navBtn navBtnText">
About
</div>
<div class="navBtn navBtnText">
Other Services
</div>
</div>
脚本:
var state = false;
$("#toggle-slide-button").click(function () {
if (!state) {
$('#navBar').animate({width: "toggle"}, 1000);
$('#toggle-slide-button img').attr('src', 'http://i.imgur.com/K3MG7gT.png');
state = true;
}
else {
$('#mnavBar').animate({width: "toggle"}, 1000);
$('#toggle-slide-button img').attr('src', 'http://i.imgur.com/8BMxPsC.png');
state = false;
}
});
如果重要,CSS:
#navBar{
background-color: #660000;
height: 780x;
width: 80px;
}
.navBtn{
background-color: #660000;
color: white;
width: 80px;
height: 70px;
cursor: pointer;
border-bottom: 1px solid rgba(255,255,255,.2);
opacity: 1;
font-size: 12px;
text-align: center;
}
.navBtnText {
line-height: 120px;
vertical-align: bottom;
}
.navBtn:hover{
background-color:#990000;
}
#navBar-control {
width: 50px;
height: 100%;
padding: 0 15px;
background-color: #000;
}
这个问题:http://jsfiddle.net/GUjPA/91/
我一直基于这个小提琴:http://jsfiddle.net/GUjPA/13/ 这具有所需的行为,只是它位于屏幕的右侧而不是左侧。我使用的脚本是完全一样的,除了侧边栏的颜色和大小不同之外,它基本上是完全一样的。
【问题讨论】:
-
你想要这样的东西吗? jsfiddle.net/GUjPA/93 或者您希望箭头与打开/隐藏的内容一起使用?
-
用
#navBar替换#mnavBar
标签: javascript jquery html jquery-animate