gpt4 book ai didi

javascript - 动画表格列以隐藏/显示它

转载 作者:太空宇宙 更新时间:2023-11-04 13:52:13 25 4
gpt4 key购买 nike

我有一个非常简单的表格,如果我按下它,我会尝试为第一列设置动画。

Full table

点击后它应该向左移动,这样它就不会再完全显示了:

animated

然后再点击一次,它应该再次动画回来

animated back again

我试图用 jquery 实现这个,但没有任何反应:

var main = function()
{
$boolean = true;

$(".test").click
(
function()
{
if ($boolean)
{
$boolean = false;
$(".test").animate
(
{
'left':'-=100px'
},
"fast"
);
}
else
{
$boolean = true;
$(".test").animate
(
{
'left':'+=100px'
},
"fast"
);
}
}
);
}
$(document).ready(main);
table {
border: 1px solid black;
}

table td {
border: 1px solid black;
}

table th {
border: 1px solid black;
}

.test {
color: red;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js"></script>
<table>
<tr>
<th class="test">Filename</th>
<th>value</th>
</tr>
<tr>
<td class="test">File1</td>
<td>Test</td>
</tr>
<tr>
<td class="test">File1</td>
<td>Test</td>
</tr>
<tr>
<td class="test">File1</td>
<td>Test</td>
</tr>
</table>

为什么它没有动画,我该如何解决?谢谢

最佳答案

这是一个有效的解决方案:

var main = function()
{
$boolean = true;

$(".test").click
(
function()
{
if ($boolean)
{
$boolean = false;
$(".test").animate
(
{
'max-width':'10px'
},
"fast"
);
}
else
{
$boolean = true;
$(".test").animate
(
{
'max-width':'300px'
},
"fast"
);
}
}
);
}
$(document).ready(main);
table {
border: 1px solid black;
}

table td {
border: 1px solid black;
}

table th {
border: 1px solid black;
}

.test {
color: red;
overflow: hidden;
max-width: 300px;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js"></script>
<table>
<tr>
<th class="test">Filename</th>
<th>value</th>
</tr>
<tr>
<td class="test">File1</td>
<td>Test</td>
</tr>
<tr>
<td class="test">File1</td>
<td>Test</td>
</tr>
<tr>
<td class="test">File1</td>
<td>Test</td>
</tr>
</table>
https://jsfiddle.net/zcb0a9tz/

关于javascript - 动画表格列以隐藏/显示它,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35173084/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com