gpt4 book ai didi

javascript - HTML:自动滚动合并表

转载 作者:行者123 更新时间:2023-12-02 15:58:36 25 4
gpt4 key购买 nike

我得到了一个表格,其中第一行被合并并显示图像:

如何让图像在页面向下滚动时自动滚动,以便图像始终位于可见(!)表格的中间?

    <table>
<tr>
<th rowspan="10">Image</th>
<th>c</th>
<th>c</th>
</tr>
<tr>
<td>c</td>
<td>c</td>
</tr>
<tr>
<td>c</td>
<td>c</td>
</tr>
<tr>
<td>c</td>
<td>c</td>
</tr>
<tr>
<td>c</td>
<td>c</td>
</tr>
<tr>
<td>c</td>
<td>c</td>
</tr>
<tr>
<td>c</td>
<td>c</td>
</tr>
<tr>
<td>c</td>
<td>c</td>
</tr>
<tr>
<td>c</td>
<td>c</td>
</tr>
<tr>
<td>c</td>
<td></td>
</tr>
</table>

最佳答案

使用 Jquery 函数 scrollTop() 并处理 滚动 事件 请参阅 Working Fiddle :

$(function($) {
var image = $('.follow-scroll');
var originalPosition = image.offset().top;

// Space between element and top of screen (when scrolling)
var topSpace = 15;

// Should probably be set in CSS; but here just for emphasis
image.css('position', 'relative');

$(window).on('scroll', function(event) {
var scrollTop = $(window).scrollTop();

image.stop(false, false).animate({
top: scrollTop < originalPosition ? 0: scrollTop - originalPosition + topSpace
}, 300);
});
});

已更新

关于javascript - HTML:自动滚动合并表,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31387500/

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