【发布时间】:2010-12-13 23:48:36
【问题描述】:
我刚开始在 Drupal 环境中使用 JQuery。
我有一些缩略图,我想要它,以便当您单击一个时,更大的图片会出现在“视口”中(出现一个隐藏的 div)。可能有更好的方法来完成我正在做的事情,但我需要这样做。
这就是我所拥有的:
$(document).ready(function() {
//$('#bigpic1').hide(); //show the first big picture always on page load
$('#bigpic2').hide();
$('#bigpic3').hide();
$('a#thumb1').click(function() {
$('#bigpic2').hide(); $('#bigpic3').hide();
$('#bigpic3').toggle(200);
return false;
});
$('a#thumb2').click(function() {
$('#bigpic1').hide(); $('#bigpic3').hide();
$('#bigpic2').toggle(200);
return false;
});
$('a#thumb3').click(function() {
$('#bigpic1').hide(); $('#bigpic2').hide();
$('#bigpic3').toggle(200);
return false;
});
});
除了是一些丑陋的代码之外,它还不能正常工作。当页面出现时,第一张大图片不会出现,单击更多缩略图会显示正确的 div - 但从不隐藏任何 div(应该在“视口”中一次只能看到一张大图片)。
我的 HTML 看起来像这样
<table><tr>
<td><a href="#" mce_href="#" id="thumb1">...thumb1...</td>
<td><a href="#" mce_href="#" id="thumb2">...thumb2...</td>
<td><a href="#" mce_href="#" id="thumb3">...thumb3...</td>
</tr>
<tr><td colspan="3">
<!-- my "viewport" cell -->
<!-- the big picture displays here -->
<div id="bigpic1">... </div>
<div id="bigpic2">...</div>
<div id="bigpic3">...</div>
</td></tr></table>
【问题讨论】:
-
你为什么要隐藏一些并切换其他的?为什么不简单地使用 hide() 和 show(),因为您实际上是手动切换图像。
-
您要关闭那些
<a>标签对吗?在您的第一个处理程序中,您应该切换#bigpic1...在这里玩的东西:jsfiddle.net/sje397/R5Fsh -
感谢您向我展示 JSFiddle!