jQuery Powered Accordion 缺少锚链接功能
对于今天的问题,我有一个使用 jQuery 工具库 构建的非常小的手风琴。我发现 jQuery 工具为我提供了所需的功能,而且占用空间比 800kb jQuery UI 小得多。更不用说更流畅、质量更好的动画了。
然而,我们现在开始填充该网站,我有点困惑的是我的手风琴中的链接不起作用。我使用了一个简单的 href="#' 作为我的占位符,突然间这些不会带我回到页面顶部。
HTML:
<div class="col">
<ul id="accordion" class="footerNav">
<li class="topLevel">
<a class="current" href="#">Autos</a>
<ul id="autos" class="pane">
<li><a href="#">News</a></li>
<li><a href="#">Reviews</a></li>
<li><a href="#">Car Tech</a></li>
<li><a href="#">Fuel Economy & Safety</a></li>
<li><a href="#">Buying & Selling</a></li>
<li><a href="#">Everything Else</a></li>
</ul>
</li>
<li class="topLevel">
<a href="#">Lifestyle</a>
<ul id="lifestyle" class="pane">
<li><a href="#">Music</a></li>
<li><a href="#">Food</a></li>
<li><a href="#">Travel</a></li>
<li><a href="#">Shopping</a></li>
<li><a href="#">Everything Else</a></li>
</ul>
</li>
<li class="topLevel">
<a href="#">People</a>
<ul id="people" class="pane">
<li><a href="#">Who You Know</a></li>
<li><a href="#">Who You Should Know</a></li>
<li><a href="#">Everyhone Else</a></li>
</ul>
</li>
<li class="topLevel">
<a href="#">Tech</a>
<ul id="tech" class="pane">
<li><a href="#">Business</a></li>
<li><a href="#">Pleasure</a></li>
<li><a href="#">Everyhting Else</a></li>
</ul>
</li>
<li class="topLevel">
<a href="#">Trends</a>
<ul id="trends" class="pane">
<li><a href="#">Online</a></li>
<li><a href="#">Offline</a></li>
<li><a href="#">Everyhting Else</a></li>
</ul>
</li>
<li><a href="#">Blog</a></li>
</ul>
</div>
CSS:
footer .col ul.footerNav li {
color:#fff;
font-family: Arial, Helvetica, sans-serif;
font-weight:100;
text-decoration:none;
list-style: url(../../images/footer_bullet_1.png);
}
footer .col ul.footerNav li.topLevel {
list-style: url(../../images/footer_bullet_3.png);
}
footer .col ul.footerNav li.topLevel:hover {
cursor:pointer;
list-style: url(../../images/footer_bullet_2.png);
}
footer .col ul.footerNav li.topLevel:active {
list-style: url(../../images/footer_bullet_2.png);
}
footer .col ul.footerNav li a {
display:block;
color:#ddd;
font-family: Arial, Helvetica, sans-serif;
font-weight:100;
text-decoration:none;
outline:none;
}
footer .col ul.footerNav li a:hover {
text-decoration:underline;
}
JAVASCRIPT:
$(document).ready(function() {
// Footer Accordion
$("#accordion").tabs("#accordion ul.pane", {
tabs: 'span',
effect: 'slide',
initialIndex: 0
});
});
要查看该网站的演示,您可以在这里:
http://rawdesigns.net/web2carz/
手风琴位于页脚的中心列中。
For today's question, I have a very small accordion I built with the jQuery Tools library. I found that jQuery tools offered me the functionality I needed, with a much smaller footprint than the 800kb jQuery UI. Not to mention smoother and better quality animation.
However, we are beginning to populate the site now, and I am a bit baffled that the links in my accordion are not working. I used a simple href="#' for my placeholders, ad suddenly those will not take me back to the top of the page.
THE HTML:
<div class="col">
<ul id="accordion" class="footerNav">
<li class="topLevel">
<a class="current" href="#">Autos</a>
<ul id="autos" class="pane">
<li><a href="#">News</a></li>
<li><a href="#">Reviews</a></li>
<li><a href="#">Car Tech</a></li>
<li><a href="#">Fuel Economy & Safety</a></li>
<li><a href="#">Buying & Selling</a></li>
<li><a href="#">Everything Else</a></li>
</ul>
</li>
<li class="topLevel">
<a href="#">Lifestyle</a>
<ul id="lifestyle" class="pane">
<li><a href="#">Music</a></li>
<li><a href="#">Food</a></li>
<li><a href="#">Travel</a></li>
<li><a href="#">Shopping</a></li>
<li><a href="#">Everything Else</a></li>
</ul>
</li>
<li class="topLevel">
<a href="#">People</a>
<ul id="people" class="pane">
<li><a href="#">Who You Know</a></li>
<li><a href="#">Who You Should Know</a></li>
<li><a href="#">Everyhone Else</a></li>
</ul>
</li>
<li class="topLevel">
<a href="#">Tech</a>
<ul id="tech" class="pane">
<li><a href="#">Business</a></li>
<li><a href="#">Pleasure</a></li>
<li><a href="#">Everyhting Else</a></li>
</ul>
</li>
<li class="topLevel">
<a href="#">Trends</a>
<ul id="trends" class="pane">
<li><a href="#">Online</a></li>
<li><a href="#">Offline</a></li>
<li><a href="#">Everyhting Else</a></li>
</ul>
</li>
<li><a href="#">Blog</a></li>
</ul>
</div>
THE CSS:
footer .col ul.footerNav li {
color:#fff;
font-family: Arial, Helvetica, sans-serif;
font-weight:100;
text-decoration:none;
list-style: url(../../images/footer_bullet_1.png);
}
footer .col ul.footerNav li.topLevel {
list-style: url(../../images/footer_bullet_3.png);
}
footer .col ul.footerNav li.topLevel:hover {
cursor:pointer;
list-style: url(../../images/footer_bullet_2.png);
}
footer .col ul.footerNav li.topLevel:active {
list-style: url(../../images/footer_bullet_2.png);
}
footer .col ul.footerNav li a {
display:block;
color:#ddd;
font-family: Arial, Helvetica, sans-serif;
font-weight:100;
text-decoration:none;
outline:none;
}
footer .col ul.footerNav li a:hover {
text-decoration:underline;
}
THE JAVASCRIPT:
$(document).ready(function() {
// Footer Accordion
$("#accordion").tabs("#accordion ul.pane", {
tabs: 'span',
effect: 'slide',
initialIndex: 0
});
});
To view a demo of the site, you can got here:
http://rawdesigns.net/web2carz/
The accordion exists in the center column of the footer.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
您在这里使用了错误的工具,
您正在使用选项卡工具执行树视图任务,您的 html 结构与库工作所需的结构完全不同。
现在,您将所有
标签视为“选项卡”,因此它们不会去任何地方,它们只是试图找到与其相关的最接近的内容,例如
显然不存在。
你只需要这段代码来制作树视图
/* CSS */ .pane { 显示:无 }
you are using the wrong tool here,
you are using the Tab tool for a Tree View task, your html structure is completely different from the one needed to the library in order to work.
as is now you are treating all the
</a>
tags as "tabs" and so they will not go anywhere, they just will trying to find the closest content related to it that is for istance a</div>
that obviously is not there.you just need this code to make that Tree View
/* CSS */ .pane { display:none }
在页面顶部使用并指定您的“#top”标签。
此外,您现在可以使用元素 ID 代替命名锚点: http://www.bennadel.com/blog/822-Using-BODY-ID-As-A-Back-To-Top-Page-Anchor.htm
Use and specify your "#top" tag at the top of the page.
Also, you can now use element ID's as instead of named anchors: http://www.bennadel.com/blog/822-Using-BODY-ID-As-A-Back-To-Top-Page-Anchor.htm
我认为它来自插件本身。查看源代码,似乎是可能的进行跨选项卡链接,这是通过以下方式完成的:
它在所有面板中查找以
#
开头的href
的所有>,它绑定了一个点击事件和处理程序调用内部“click”方法
self.click
,用于切换选项卡。您的链接属于这种情况,因此被视为跨表链接。
我认为将链接更改为
不会解决问题,因为它们仍会被视为跨选项卡链接。它不会像你想要的那样工作。
I think it comes from the plugin itself. Looking at the source code, it seems it is possible to make cross-tab linking, and this is done this way:
It finds all
<a>
in all panels withhref
starting with a#
, it binds a click event and the handler calls the internal "click" methodself.click
, used to switch tabs.Your links falls in this scenario and thus are considered cross-tab links.
I don't think changing your links to
<a href="#top">
would resolve the problem as they will still be considered as cross-tab links. it will just won't work as such, or as you want.