有没有更简单的方法来使用 jQuery 手风琴?

发布于 2024-08-27 21:31:46 字数 552 浏览 10 评论 0原文

我一直在努力解决我一直试图创建的功能。 这里的想法是,用户看到小缩略图+标题,以及发布者信息。然后,他们可以单击标题展开到文章,或单击“评论”链接直接展开到对文章的评论。或者,如果他们愿意,可以通过单击标题(展开到文章)来查看评论,然后单击“查看评论”(展开到评论)。最后,一个模块化但灵活且功能齐全的打开/关闭系统可以查看最新新闻。

这是我一直在做的事情:(我把所有代码放在一个地方,这样任何人都可以更轻松地查看)http://notedls.com/pointtest.html

这就是我正在拍摄的目标,但它离我想要的还很远;( 它使用 jQuery 1.6 插件,1.8 版本已经发布,但我还远远不是这方面的大师或专家,而且我不认为我可以从头开始构建。我已经编辑了这个插件,让它像这样工作,但是正如你所看到的,作者和评论开始让粉丝们大吃一惊;;这是因为代码正在调用标头的“A TAG”;这是标题。

有谁知道有什么更简单的方法来实现我的设想或者可能的方法来修复当前的代码?此时我非常绝望;;

I've been struggling with a feature I've been trying to create for sometime.
The idea here is that the user sees the little thumbnail + headline, as well as the Posted By information. They can then click on the headline to expand to the article or click on the "Comments" link to expand directly to the comments made on the article. Or, if they want they can view comments by clicking on the headline(to expand to the article), then click on View Comments (to expand to the comments). In the end, a modular yet flexible and functional open/close system to view latest news.

Here is what I've been working on: (I put all my code in one place so its easier on whomever may look at this to view) http://notedls.com/pointtest.html

This is what I'm shooting for, but it's far from what I want ;(
It's using the jQuery 1.6 plugin, which 1.8 is out but I'm far from being a master or expert at this and I don't think I could build from the ground up. I've already edited this plugin to get it to work like this, but as you can see, the AUTHOR and Comments start making shit hit the fan ;; It's because the code is calling the "A TAG" for the header; which is the headline.

Does anyone know any easier way to achieve what I'm envisioning or possible a way to fix this current code? I'm pretty desperate at this point ;;

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

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

发布评论

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

评论(2

记忆で 2024-09-03 21:31:46

像这样的东西:?

http://jsbin.com/elawu

替代文字

这是一把手风琴。每个“第一个元素”或标题都是一个 div。该标题中包含文章标题、作者和列出该文章评论数量的可点击范围。

每个“第二个元素”,或者手风琴的内容部分,也是一个 div。该 div 中有一个文章内容 div 和评论 div。在评论 div 中,有一个评论标题(同样可点击)和另一个内容 div。层次结构如下所示:

<div id='outer-accordion'>
   <div class='header'>
      <p>Article headline</p>
      <p>by: Author</p>
      <p><span class='clickable'># comments</span></p>
   </div>
   <div class='content'>
      <div class='article'>...</div>
      <div class='comments'>
        <p><span class='clickable'># of comments</span></p>
        <div class='comment-content'>
           comment #1
           comment #2
           ...
        </div>
      </div>
   </div>

   ....

当页面启动时,所有评论内容 div 都会通过 $('div.comments div').hide(); 隐藏,同时手风琴也会被设置,并且手风琴 < code>onaccordionchange 和 onaccordionchangestart 事件被绑定。最后,为评论链接注册一个点击事件。

如果单击标题上的任意位置,则会弹出关联的手风琴内容选项卡。如果您单击标题中的评论链接,它将打开手风琴,打开内容 div 中的评论 div。

每当打开手风琴选项卡时,标题中的评论链接就会被隐藏。每当手风琴选项卡关闭时,标题中的评论链接都会显示。

单击手风琴内容 div 中的评论链接可切换实际评论。

Something like this:?

http://jsbin.com/elawu

alt text

It's an accordion. Each "first element", or header, is a div. Within that header is an article headline, an author, and a clickable span listing the number of comments for that article.

Each "second element", or content portion of the accordion, is also a div. Within that div there is an article content div, and comments div. Within the comments div there is a comment header, again clickable, and another content div. The hierarchy looks like this:

<div id='outer-accordion'>
   <div class='header'>
      <p>Article headline</p>
      <p>by: Author</p>
      <p><span class='clickable'># comments</span></p>
   </div>
   <div class='content'>
      <div class='article'>...</div>
      <div class='comments'>
        <p><span class='clickable'># of comments</span></p>
        <div class='comment-content'>
           comment #1
           comment #2
           ...
        </div>
      </div>
   </div>

   ....

When the page starts all the comment content divs get hidden via $('div.comments div').hide(); Also the accordion gets set up, and the accordion onaccordionchange and onaccordionchangestart events get bound. Finally, a click event is registered for the Comments links.

If you click anywhere on the header, it pops open the associated accordion content tab. If you click on the comments link in the header, it opens the accordion, and opens the comments div within the content div.

Any time an accordion tab gets opened, the comments link in the header gets hidden. Any time an accordion tab closes, the comments link in the header gets shown.

Clicking on the comments link within the accordion content div, toggles the actual comments.

月下伊人醉 2024-09-03 21:31:46

哦,我觉得我明白了

$('.author').click(function() {
    $(this).parent().find('.authordiv').toggleClass('hidden');
});
$('.comments').click(function() {
    $(this).parent().find('.commentsdiv').toggleClass('hidden');
});

并使用隐藏的 css 类

.hidden {
    display:none;
}

oh, i feel i get it

$('.author').click(function() {
    $(this).parent().find('.authordiv').toggleClass('hidden');
});
$('.comments').click(function() {
    $(this).parent().find('.commentsdiv').toggleClass('hidden');
});

and use hidden css class

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