gpt4 book ai didi

javascript - 使 JQueryMobile 表可滚动?

转载 作者:行者123 更新时间:2023-11-28 16:07:39 27 4
gpt4 key购买 nike

大家好,有没有办法使用 Jquery Mobile 使表格可滚动?找不到适合我的目的的解决方案。

假设我有一张这样的 table :fiddle

<table data-role="table" class="ui-responsive ui-shadow gk-decorate testClass" id="someId" is="jqm-table" style="margin-left: %; width: %">
<thead>
<tr>
<th data-priority="1">Title_1</th>
<th data-priority="1">Title_2</th>
<th data-priority="1">Title_3</th>
<th data-priority="1">Title_4</th>
<th data-priority="1">Title_5</th>
<th data-priority="1">Title_6</th>
</tr>
</thead>
<tbody>
<tr>
<th>Content_1</th>
<td>Content_2</td>
<td>Content_3</td>
<td>Content_4</td>
<td>Content_5</td>
<td>Content_6</td>
</tr>
<tr>
<th>Content_1</th>
<td>Content_2</td>
<td>Content_3</td>
<td>Content_4</td>
<td>Content_5</td>
<td>Content_6</td>
</tr>
<tr>
<th>Content_1</th>
<td>Content_2</td>
<td>Content_3</td>
<td>Content_4</td>
<td>Content_5</td>
<td>Content_6</td>
</tr>
<tr>
<th>Content_1</th>
<td>Content_2</td>
<td>Content_3</td>
<td>Content_4</td>
<td>Content_5</td>
<td>Content_6</td>
</tr>
<tr>
<th>Content_1</th>
<td>Content_2</td>
<td>Content_3</td>
<td>Content_4</td>
<td>Content_5</td>
<td>Content_6</td>
</tr>
</tbody>

我的问题是我希望表格只显示 5 行,其余的应该可以通过滚动访问。这可能吗?

最佳答案

如果这对您来说足够了,您可以将容器 div 设置为 overflow:scroll在 y 方向并给它一个固定的高度。要修复标题行,只需在内容中添加 <span> 即可标记并将其设置为 position:fixed .现在给第一个内容行顶部一点空间(例如作为填充),你就完成了:

div {
overflow-y: scroll;
height: 100px;
}
table {
width: 100%;
}
thead th {
position: relative;
}
thead th span {
position: fixed;
background: white;
}
table tbody tr:first-child th,
table tbody tr:first-child td {
padding-top: 20px;
}
<div>
<table data-role="table" class="ui-responsive ui-shadow gk-decorate testClass" id="someId" is="jqm-table">
<thead>
<tr>
<th data-priority="1"><span>Title_1</span></th>
<th data-priority="1"><span>Title_2</span></th>
<th data-priority="1"><span>Title_3</span></th>
<th data-priority="1"><span>Title_4</span></th>
<th data-priority="1"><span>Title_5</span></th>
<th data-priority="1"><span>Title_6</span></th>
</tr>
</thead>
<tbody>
<tr>
<th>Content_1</th>
<td>Content_2</td>
<td>Content_3</td>
<td>Content_4</td>
<td>Content_5</td>
<td>Content_6</td>
</tr>
<tr>
<th>Content_1</th>
<td>Content_2</td>
<td>Content_3</td>
<td>Content_4</td>
<td>Content_5</td>
<td>Content_6</td>
</tr>
<tr>
<th>Content_1</th>
<td>Content_2</td>
<td>Content_3</td>
<td>Content_4</td>
<td>Content_5</td>
<td>Content_6</td>
</tr>
<tr>
<th>Content_1</th>
<td>Content_2</td>
<td>Content_3</td>
<td>Content_4</td>
<td>Content_5</td>
<td>Content_6</td>
</tr>
<tr>
<th>Content_1</th>
<td>Content_2</td>
<td>Content_3</td>
<td>Content_4</td>
<td>Content_5</td>
<td>Content_6</td>
</tr>
<tr>
<th>Content_1</th>
<td>Content_2</td>
<td>Content_3</td>
<td>Content_4</td>
<td>Content_5</td>
<td>Content_6</td>
</tr>
<tr>
<th>Content_1</th>
<td>Content_2</td>
<td>Content_3</td>
<td>Content_4</td>
<td>Content_5</td>
<td>Content_6</td>
</tr>
<tr>
<th>Content_1</th>
<td>Content_2</td>
<td>Content_3</td>
<td>Content_4</td>
<td>Content_5</td>
<td>Content_6</td>
</tr>
<tr>
<th>Content_1</th>
<td>Content_2</td>
<td>Content_3</td>
<td>Content_4</td>
<td>Content_5</td>
<td>Content_6</td>
</tr>
<tr>
<th>Content_1</th>
<td>Content_2</td>
<td>Content_3</td>
<td>Content_4</td>
<td>Content_5</td>
<td>Content_6</td>
</tr>
<tr>
<th>Content_1</th>
<td>Content_2</td>
<td>Content_3</td>
<td>Content_4</td>
<td>Content_5</td>
<td>Content_6</td>
</tr>
<tr>
<th>Content_1</th>
<td>Content_2</td>
<td>Content_3</td>
<td>Content_4</td>
<td>Content_5</td>
<td>Content_6</td>
</tr>
</tbody>
</table>
</div>

关于javascript - 使 JQueryMobile 表可滚动?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38895723/

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