Jquery 在表中显示和隐藏
我有一个包含内容和图像的表格,单击该表格会显示 div 中包含的隐藏内容。该 div 内有另一个表格用于格式化内容。现在,当我在 IE 和 Chrome 中测试此功能时,隐藏内容会根据单击的按钮上下滑动。但是当我在 Firefox 中执行此操作时,内容只是出现并消失,没有平滑的滑动。谁能告诉我为什么。如果我将显示按钮移出顶部表格并将其插入两个表格之间,则上下滑动可以顺利进行。唯一的问题是我需要将显示按钮放在
我的脚本的内容中,它看起来像这样
<script type="text/javascript">
//<![CDATA[
$(function() {
$(document).ready(function() {
$(".slidingDiv").hide()
$('.show').click(function() {
$(".slidingDiv").slideDown(1000);
return false;
});
$('.hide').click(function() {
$(".slidingDiv").slideUp(1000);
return false;
});
});
});
//]]>
</script>
,它出现在页面的头部,
然后我的页面正文的代码看起来像
<table style="width: 100%;" align="left" border="0">
<tbody>
<tr>
<td>content here</td>
<td>and here</td>
<td><a class="show"><img src="images/more.jpg" onmouseout="this.src='images/more.jpg';" onmouseover="this.src='images/more_over.jpg';" /></a></td>
</tr>
</tbody>
</table>
<div class="slidingDiv">
<table style="width: 100%;" align="left" border="0">
<tbody>
<tr>
<td>content hidden</td>
<td>content hidden</td>
<td>content hidden</td>
</tr>
<tr>
<td>content hidden</td>
<td>content hidden</td>
</tr>
<tr>
<td>content hidden</td>
<td>content hidden</td>
</tr>
</tbody>
</table>
<a class="hide"><img src="images/close.jpg" onmouseout="this.src='images/close.jpg';" onmouseover="this.src='images/close_over.jpg';" /></a>
</div>
I have a table with content and a image that when clicked shows hidden content contained within a div. This div has another table within to format the content. Now when i test this in IE and chrome the hidden content slides up and down depending on the button clicked. But when i do this in firefox the content just appears and disappears no smooth sliding. Can anyone tell me why. If i move the show button out of the top table and insert it between the two tables the sliding up and down works smoothly. The only problem with this is that i need the show button to be within the content
my script looks like this
<script type="text/javascript">
//<![CDATA[
$(function() {
$(document).ready(function() {
$(".slidingDiv").hide()
$('.show').click(function() {
$(".slidingDiv").slideDown(1000);
return false;
});
$('.hide').click(function() {
$(".slidingDiv").slideUp(1000);
return false;
});
});
});
//]]>
</script>
which appears in the head of the page
then my code for the body of the page looks like
<table style="width: 100%;" align="left" border="0">
<tbody>
<tr>
<td>content here</td>
<td>and here</td>
<td><a class="show"><img src="images/more.jpg" onmouseout="this.src='images/more.jpg';" onmouseover="this.src='images/more_over.jpg';" /></a></td>
</tr>
</tbody>
</table>
<div class="slidingDiv">
<table style="width: 100%;" align="left" border="0">
<tbody>
<tr>
<td>content hidden</td>
<td>content hidden</td>
<td>content hidden</td>
</tr>
<tr>
<td>content hidden</td>
<td>content hidden</td>
</tr>
<tr>
<td>content hidden</td>
<td>content hidden</td>
</tr>
</tbody>
</table>
<a class="hide"><img src="images/close.jpg" onmouseout="this.src='images/close.jpg';" onmouseover="this.src='images/close_over.jpg';" /></a>
</div>
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
检查这个 JSFiddle: http://jsfiddle.net/s3Fpt/3/ (1)
这适用于Firefox
似乎 div 和表格中的
align="left" border="0"
都会对动画产生负面影响。这不是问题,因为您应该只使用 HTML 定义文档,而不是设置其样式。此外,align 是一个已弃用的属性,无论如何都应该避免。可以使用 css 来设置对齐和边框的样式:
(1) edit:删除了额外的函数包装,正如 ScottE 所注意到的
Check this JSFiddle: http://jsfiddle.net/s3Fpt/3/ (1)
This works in Firefox
It seems that
align="left" border="0"
in both your div and table negatively influence the animation. That's not a problem, because you should only define your document with HTML, not style it. Furthermore, align is a deprecated attribute and should be avoided anyway.Styling the alignment and the border can be done with css:
(1) edit: removed the extra function wrapping, as noticed by ScottE