切换和动画锚链接不再导航
我使用 jQuery.toggle 和 .animate 作为位于页面底部的导航菜单。导航由两个 div 组成,一个作为外部容器,另一个作为包含导航按钮等的内部容器。
我想要实现的是;您单击导航,它的位置会向上移动,要关闭导航,您只需再次单击它,它就会以动画方式返回到页面底部的原始位置。
我遇到的问题是,当您单击导航按钮时,没有任何反应,即使浏览器状态栏显示目标 URL,它也不会像应有的那样将您带到链接。
这是链接
jQuery:
$('#navContainer').toggle(function() {
$('#navInner').animate({
bottom: '+=350'
}, 400, 'swing', function() {
});
}, function() {
$('#navInner').animate({
bottom: '-=350'
}, 400, 'swing', function() {
});
});
CSS:
#navContainer {
background-color:#0FF;
height:520px;
margin:0px 0px 0px 60px;
position:fixed;
cursor:pointer;
bottom: 0px;
}
#navInner {
background:url(../images/appinstructions/nav2.png);
background-repeat:no-repeat;
width:638px;
height:491px;
position:absolute;
bottom:-350px;
}
HTML:
<div id="navContainer">
<div id="navInner">
<a id="navhomeBtn" href="appInstuc.html"></a>
<a id="navhelpBtn" href="appInstuc.html"></a>
<a id="geBtn" href="http://www.ge.com/" target="_blank"></a>
<div id="pages">
<a href="ipadApp1.html"><img src="images/appinstructions/page1.png" alt="page 1" class="page"/></a>
<a href="app1-1.html"><img src="images/appinstructions/page2.png" alt="page 2" class="page"/></a>
<a href="appRoots.html"><img src="images/appinstructions/page3.png" alt="page3"class="page"/></a>
</div><!--close pages-->
</div><!--close navInner-->
</div><!--close navContainer-->
I am using jQuery.toggle and .animate for a navigation menu that sits at the bottom of the page. The nav consists of two divs, one as a outer container and the other as a inner container that holds the nav buttons etc.
What I am trying to achieve is; you click on the nav and it's position animates up and to close the nav you simply click on it again and it animates back down to it's original position at the bottom of the page.
The issue I am having is when you click on the nav buttons nothing happens, it doesn't take you to the link like it should even though the browser status bar shows the target URL.
Here's a link
jQuery:
$('#navContainer').toggle(function() {
$('#navInner').animate({
bottom: '+=350'
}, 400, 'swing', function() {
});
}, function() {
$('#navInner').animate({
bottom: '-=350'
}, 400, 'swing', function() {
});
});
CSS:
#navContainer {
background-color:#0FF;
height:520px;
margin:0px 0px 0px 60px;
position:fixed;
cursor:pointer;
bottom: 0px;
}
#navInner {
background:url(../images/appinstructions/nav2.png);
background-repeat:no-repeat;
width:638px;
height:491px;
position:absolute;
bottom:-350px;
}
HTML:
<div id="navContainer">
<div id="navInner">
<a id="navhomeBtn" href="appInstuc.html"></a>
<a id="navhelpBtn" href="appInstuc.html"></a>
<a id="geBtn" href="http://www.ge.com/" target="_blank"></a>
<div id="pages">
<a href="ipadApp1.html"><img src="images/appinstructions/page1.png" alt="page 1" class="page"/></a>
<a href="app1-1.html"><img src="images/appinstructions/page2.png" alt="page 2" class="page"/></a>
<a href="appRoots.html"><img src="images/appinstructions/page3.png" alt="page3"class="page"/></a>
</div><!--close pages-->
</div><!--close navInner-->
</div><!--close navContainer-->
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
问题似乎出在
.toggle
函数上,如果您使用.click
链接就可以工作。使用.toggle
链接不起作用的原因是这些链接是#navInner div
的子级,因此单击链接会触发.toggle
代码>事件。我建议改为这样做:
这将为您提供切换方法的效果,但如果您单击其中一个子元素,它不会为
#navInner div
设置动画。如果您确实希望它仍然对
#navInner div
进行动画处理,只需删除以下行:(尽管因为它们是链接并将您带到不同的页面,所以我怀疑对
#navInner div 进行动画处理div
是需要的)The problem seems to be with the
.toggle
function, if you use.click
the links work. The reason the links don't work using.toggle
is because the links are children of the#navInner div
, so clicking the link fires the.toggle
event.I would suggest doing something like this instead:
This will give you the effect of the toggle method, but if you click one of the child elements it will not animate the
#navInner div
.If you do want it to still animate the
#navInner div
, just remove the following line:(although because they are links and taking you off to a different page, I doubt animating the
#navInner div
is need)