jQuery 手风琴不适合我

发布于 2024-12-10 15:40:27 字数 1661 浏览 0 评论 0原文

我正在寻找使用 jQuery 手风琴的一些帮助。

基本上,我的元素不是开箱即用的标准 h3 和 p 标签。

我的 jQuery 如下

<script>
jQuery(document).ready(function() {
    jQuery("#contentHolder").accordion({
        header: '.clicker'
    });
});
</script>

,我使用的 HTML 如下:

<div id="contentHolder">

<div id="recipe">
    <img src="style/img/rec-image.jpg"></img>
    <p><span style="color: #5C971C; font-weight: bold;">Stuffs M</span><br />stuff goes here</p>
    <p><a class="clicker" href="#"><img src="style/img/details-btn.jpg"></img></a></p>
    <div class="ingredients" style="margin-top: 136px;">
        <p style="width: 420px;"><span style="color: #5C971C; font-weight: bold;">Ingredients</span><br />2L white vinegar<br />2 cups water</p>
    </div>
</div>

<div id="recipe">
    <img src="style/img/rec-image.jpg"></img>
    <p><span style="color: #5C971C; font-weight: bold;">Stuffs M</span><br />stuff goes here</p>
    <p><a class="clicker" href="#"><img src="style/img/details-btn.jpg"></img></a></p>
    <div class="ingredients" style="margin-top: 136px;">
        <p style="width: 420px;"><span style="color: #5C971C; font-weight: bold;">Ingredients</span><br />2L white vinegar<br />2 cups water</p>
    </div>
</div>

</div>

我希望它如何工作,就是当有人单击 .clicker href 时,我希望 div“成分”上下滑动。

我希望有人能提供帮助:)

干杯,

Im looking for a bit of help using the jQuery accordion.

Basically, i have elements that arent the standard h3 and p tags that it requires out of the box.

The jQuery i have is as follows

<script>
jQuery(document).ready(function() {
    jQuery("#contentHolder").accordion({
        header: '.clicker'
    });
});
</script>

and the HTML that im using is as follows:

<div id="contentHolder">

<div id="recipe">
    <img src="style/img/rec-image.jpg"></img>
    <p><span style="color: #5C971C; font-weight: bold;">Stuffs M</span><br />stuff goes here</p>
    <p><a class="clicker" href="#"><img src="style/img/details-btn.jpg"></img></a></p>
    <div class="ingredients" style="margin-top: 136px;">
        <p style="width: 420px;"><span style="color: #5C971C; font-weight: bold;">Ingredients</span><br />2L white vinegar<br />2 cups water</p>
    </div>
</div>

<div id="recipe">
    <img src="style/img/rec-image.jpg"></img>
    <p><span style="color: #5C971C; font-weight: bold;">Stuffs M</span><br />stuff goes here</p>
    <p><a class="clicker" href="#"><img src="style/img/details-btn.jpg"></img></a></p>
    <div class="ingredients" style="margin-top: 136px;">
        <p style="width: 420px;"><span style="color: #5C971C; font-weight: bold;">Ingredients</span><br />2L white vinegar<br />2 cups water</p>
    </div>
</div>

</div>

How i want it to work, is when someone clicks on the .clicker href i want the div "ingredients" to slide up and down.

Im hoping someone can help :)

Cheers,

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

反差帅 2024-12-17 15:40:27

根据 jQuery UI Accordian 文档

The content element must be always next to its header.

您的“点击器”位于 p 元素内部

<p><a class="clicker" href="#"><img src="style/img/details-btn.jpg"></img></a></p>

也许将“点击器”放在 p 元素上?或者去掉 p 元素。只需确保您尝试显示的 div 是 DOM 中的“下一个”元素即可。

According to jQuery UI Accordian docs

The content element must be always next to its header.

Your "clicker" is inside of a p-element

<p><a class="clicker" href="#"><img src="style/img/details-btn.jpg"></img></a></p>

Maybe put the "clicker" on the p-element? Or get rid of the p-element. Just make sure the div you are trying to show is the "next" element in the DOM.

爺獨霸怡葒院 2024-12-17 15:40:27

手风琴需要以下结构:

<div id="contentHolder">
    <div class="clicker">
        <a href="#">first clickable</a>
    </div>
    <div>
        first content
    </div>

    <div class="clicker">
        <a href="#">next clickable</a>
    </div>
    <div>
        next content
    </div>
</div>

另请参阅在此 jsfiddle 中工作的示例。

===更新===

虽然我忘了说这不一定是'div'需要执行的操作,但是对于每个块元素:

<div id="contentHolder">
    <p class="clicker">
        <a href="#">
            <img src="style/img/rec-image.jpg" /><br />
            <span style="color: #5C971C; font-weight: bold;">Stuffs M</span><br />
            stuff goes here<br />
            <img src="style/img/details-btn.jpg" />
        </a>
    </p>
    <p class="ingredients">
        <span style="color: #5C971C; font-weight: bold;">Ingredients</span><br />
        2L white vinegar<br />
        2 cups water
    </p>

    <p class="clicker">
        <a href="#">
            <img src="style/img/rec-image.jpg" /><br />
            <span style="color: #5C971C; font-weight: bold;">Stuffs M</span><br />
            stuff goes here<br />
            <img src="style/img/details-btn.jpg" />
        </a>
    </p>
    <p class="ingredients">
        <span style="color: #5C971C; font-weight: bold;">Ingredients</span><br />
        2L white vinegar<br />
        2 cups water
    </p>
</div>

另请参阅我更新的jsfiddle.

The accordion needs following structure:

<div id="contentHolder">
    <div class="clicker">
        <a href="#">first clickable</a>
    </div>
    <div>
        first content
    </div>

    <div class="clicker">
        <a href="#">next clickable</a>
    </div>
    <div>
        next content
    </div>
</div>

Also see your example working in this jsfiddle.

=== UPDATE ===

Although I had forgotten to say that this is not necessarily 'div' s need to act, but to each block element:

<div id="contentHolder">
    <p class="clicker">
        <a href="#">
            <img src="style/img/rec-image.jpg" /><br />
            <span style="color: #5C971C; font-weight: bold;">Stuffs M</span><br />
            stuff goes here<br />
            <img src="style/img/details-btn.jpg" />
        </a>
    </p>
    <p class="ingredients">
        <span style="color: #5C971C; font-weight: bold;">Ingredients</span><br />
        2L white vinegar<br />
        2 cups water
    </p>

    <p class="clicker">
        <a href="#">
            <img src="style/img/rec-image.jpg" /><br />
            <span style="color: #5C971C; font-weight: bold;">Stuffs M</span><br />
            stuff goes here<br />
            <img src="style/img/details-btn.jpg" />
        </a>
    </p>
    <p class="ingredients">
        <span style="color: #5C971C; font-weight: bold;">Ingredients</span><br />
        2L white vinegar<br />
        2 cups water
    </p>
</div>

Also see my updated jsfiddle.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文