jQuery 手风琴问题
我正在尝试根据幻灯片打开一些 DIV 使用 jQuery UI。我希望链接位于其他位置,并根据其 ID 定位特定的 DIV。我该怎么做呢?有什么建议可以指引我正确的方向吗?
有点像这样:
<script>
jQuery().ready(function() {
jQuery("#accordion" ).accordion({
collapsible: true,
active: false,
navigation: true
});
});
</script>
和:
<h3><a href="#1">Section 1</a></h3>
<h3><a href="#2">Section 2</a></h3>
<h3><a href="#3">Section 3</a></h3>
<h3><a href="#4">Section 4</a></h3>
<div id="accordion">
<div id="1">
<p>content</p>
</div>
<div id="2">
<p>content</p>
</div>
<div id="3">
<p>content</p>
</div>
<div id="4">
<p>content</p>
</div>
</div>
I'm trying to using the jQuery UI according to slide open some DIVs. I want the links to be located elsewhere and target the specific DIVs dependent on their ID. How would I go about doing this? Any tips to point me in the right direction?
Something sort of like this:
<script>
jQuery().ready(function() {
jQuery("#accordion" ).accordion({
collapsible: true,
active: false,
navigation: true
});
});
</script>
and:
<h3><a href="#1">Section 1</a></h3>
<h3><a href="#2">Section 2</a></h3>
<h3><a href="#3">Section 3</a></h3>
<h3><a href="#4">Section 4</a></h3>
<div id="accordion">
<div id="1">
<p>content</p>
</div>
<div id="2">
<p>content</p>
</div>
<div id="3">
<p>content</p>
</div>
<div id="4">
<p>content</p>
</div>
</div>
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
您是否试图在单击页面上其他位置时使手风琴上下滑动?如果您是,那么我只需调用您想要单击的手风琴标题的单击事件。
例如,使用以下手风琴标记:
当单击链接“activateAccordion”时,您可以使第 1 部分向上滑动,如下所示:
You are trying to make an accordion slide up and down when clickig elsewhere on the page? If you are then I would just call the click event of the accordion heading you wish to click.
For example with the following accordion markup:
You could make section 1 slide up down when clicking the link 'activateAccordion' like so:
这是解决方案的jsfiddle。
稍微修改了 HTML:(注意
class
和href
属性):JS 使用
activate
方法:需要注意的一件事:
href
属性参数传递到activate
方法中被解释为 CSS 选择器,它方便地(并且巧合地)以#
选择器开头,因此它“仅适用于”任何有效的 ID。Here's a jsfiddle of the solution.
Slightly modified HTML: (notice the
class
andhref
attributes):JS using the
activate
method:One thing to note: the
href
attribute argument passed into theactivate
method is interpreted as a CSS selector, which conveniently (and coincidentally) starts with the#
selector, so it "just works" with any valid ID.您可以使用激活方法。
签名:
以编程方式激活 Accordion 的内容部分。索引可以是零索引数字,以匹配要关闭的标头的位置,也可以是匹配元素的选择器。传递 false 来关闭所有(仅适用于 collapsible:true)。
使用
$(link).click(function(){})
购买,您可以选择被点击元素的id并在 activate 方法的索引中传递 id,例如:
You can use the activate method.
Signature:
Activate a content part of the Accordion programmatically. The index can be a zero-indexed number to match the position of the header to close or a Selector matching an element. Pass false to close all (only possible with collapsible:true).
Buy using
$(link).click(function(){})
, you can select the id of the clicked element andpass the id in the index of the activate method like:
你想要看起来更像这样的东西。
You want something that looks more like this.