【发布时间】:2023-04-01 03:36:01
【问题描述】:
当 colgroup 宽度改变时,过渡不起作用。
$('#but').click(function() {
if ($('table col').hasClass("expanded"))
$('table col').removeClass('expanded');
else
$('table col').addClass('expanded');
});
table,
th,
td {
border: 1px solid black;
}
table col {
-webkit-transition: width .8s ease;
-moz-transition: width .8s ease;
-ms-transition: width .8s ease;
-o-transition: width .8s ease;
transition: width .8s ease;
}
.expanded {
width: 200px
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js"></script>
<button id="but">Button</button>
<table>
<colgroup>
<col></col>
<col></col>
</colgroup>
<tr>
<th>Month</th>
<th>Savings</th>
</tr>
<tr>
<td>January</td>
<td>$100</td>
</tr>
</table>
我正在使用此代码。在此代码中,CSS 过渡属性将不起作用。 transition: width .8s ease;
【问题讨论】:
-
在没有
expandedfront-back.com/…类的情况下为table col提供宽度时有效
标签: javascript jquery css css-transitions