如何修复这个 jQuery SlideToggle?
我想做的是,当单击 dl/dt 库中的这些图像时,在一行图像下独立地滑动切换文本 div,如下所示:
但当然我至少做错了一些事情。标记位于 jQuery 选项卡中可能会很复杂,但情况可能并非如此。 jsfiddle在这里: http://jsfiddle.net/Yfs2V/8/
我认为该函数有问题:
jQuery 函数:
$(".bkcontent").hide();
$("#bookimggallery dt").click(function() {
$(".bkcontent").hide();
$(this).parent().children(".bkcontent").slideToggle(500); });
HTML:
<div id="bookimggallery">
<dl class="gallery"><dt><img alt="img" src=""></dt>
<dt>Image Title One</dt></dl>
<dl class="gallery"><dt><img alt="img" src=""></dt>
<dt>Image Title Two</dt></dl>
<dl class="gallery"><dt><img alt="img" src=""></dt>
<dt>Image Title Three</dt></dl>
<dl class="gallery"><dt><img alt="img" src=""></dt>
<dt>Image Title Four</dt></dl>
<dl class="gallery"><dt><img alt="img" src=""></dt>
<dt>Image Title Five</dt></dl>
</div>
<div id="booktextdiv">
<div class="bkcontent">Lorum Ipsum....</div>
<div class="bkcontent">Lorum Ipsum....</div>
<div class="bkcontent">Lorum Ipsum....</div>
<div class="bkcontent">Lorum Ipsum....</div>
<div class="bkcontent">Lorum Ipsum....</div>
</div>
CSS:
#bookimggallery { width: 600px; height:200px; margin:2px; text-align: center;}
dl.gallery {width: 93px; text-align: center; float: left;}
.gallery dt { width: 80px; margin-top:2px; font-size: .7em; text-align:center;}
#booktextdiv span {display:none}
*(omitted tabs CSS for clairity)*
What I'm trying to do is independently slidetoggle text divs under a row of images when those images - in a dl/dt gallery - are clicked, like so:
But of course I'm doing at least a few things wrong. Could be complicated that the markup is in a jQuery Tab, but that may not be the case. jsfiddle here: http://jsfiddle.net/Yfs2V/8/
I think the function is problematic:
jQuery function:
$(".bkcontent").hide();
$("#bookimggallery dt").click(function() {
$(".bkcontent").hide();
$(this).parent().children(".bkcontent").slideToggle(500); });
the HTML:
<div id="bookimggallery">
<dl class="gallery"><dt><img alt="img" src=""></dt>
<dt>Image Title One</dt></dl>
<dl class="gallery"><dt><img alt="img" src=""></dt>
<dt>Image Title Two</dt></dl>
<dl class="gallery"><dt><img alt="img" src=""></dt>
<dt>Image Title Three</dt></dl>
<dl class="gallery"><dt><img alt="img" src=""></dt>
<dt>Image Title Four</dt></dl>
<dl class="gallery"><dt><img alt="img" src=""></dt>
<dt>Image Title Five</dt></dl>
</div>
<div id="booktextdiv">
<div class="bkcontent">Lorum Ipsum....</div>
<div class="bkcontent">Lorum Ipsum....</div>
<div class="bkcontent">Lorum Ipsum....</div>
<div class="bkcontent">Lorum Ipsum....</div>
<div class="bkcontent">Lorum Ipsum....</div>
</div>
the CSS:
#bookimggallery { width: 600px; height:200px; margin:2px; text-align: center;}
dl.gallery {width: 93px; text-align: center; float: left;}
.gallery dt { width: 80px; margin-top:2px; font-size: .7em; text-align:center;}
#booktextdiv span {display:none}
*(omitted tabs CSS for clairity)*
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
这里有几个问题。我认为主要是您用来访问书籍点击的选择器,而且它的文本似乎没有以任何方式链接到书籍库项目。
我在此处稍微修改了代码
基本更改是HTML :
将
rel="blahh"
添加到每本书的dl
中,这将对应于文本 div添加
id="blah"
到包含本书文本的div
jQuery 更改:
div
中带有id="bookimggallery"
的所有dt
。rel="blah"
获取 id,然后滑动切换它。在不完全重新安排代码布局的情况下,这就是我的做法。
There are a couple of problems going on here. I think the main being the selectors you are using to access the click on the book and also its text doesn't appear to be linked to the book gallery item in any way.
I have modified your code slightly here
The basic changes are HTML:
Add a
rel="blahh"
to thedl
of each book, this will correspond to the text divAdd an
id="blah"
to thediv
that contains the text for the bookThe jQuery changes:
dt
's within thediv
with theid="bookimggallery"
rel="blah"
, then slideToggles it.Without completely rearranging your code layout this is how I would do this.
对于一个类,您的类是
bookimggallery
而不是imagegallerydiv
,对于另一个类,文本不是您的元素的子元素,因此 < code>$(this).parent().children(".bkcontent") 不包含任何元素。
Well for one your class is
bookimggallery
and notimagegallerydiv
, for another, the text is not a child of your<dl>
elements so$(this).parent().children(".bkcontent")
doesn't contain any elements.检查此参考,看起来您对 DL/DT 的使用/DD 略有偏差。
考虑将您的 html 重新组织为
您的 jquery 然后看起来像
Checking this reference it looks like your use of DL/DT/DD is slightly off.
Consider reorganizing your html to
Your jquery would then look like