gpt4 book ai didi

javascript - jquery scrollToFixed 在到达页面顶部时停止

转载 作者:太空宇宙 更新时间:2023-11-03 18:55:02 26 4
gpt4 key购买 nike

jquery scrollToFixed 在到达页面最顶部时停止,它只是出现在本应固定在最顶部的 div 的顶部。

Here is what I have so far .

var arr = new Array();
$('div[id^="post"]').each(function()
{
// do something with it...
var id = $(this).attr("id").slice(5);
//alert(id);

arr.push(id);

$(this).css('background-color', 'green');
});

for (i = 0; i < $('div[id^="post"]').length; i++) {
//alert(arr[i+1]);

$('#float-'+arr[i]).scrollToFixed({
limit: $('#post-'+arr[i+1]).offset().top - $('#float-'+arr[i]).height()-220
});
}​

我正在使用 jquery scrollToFixed 插件。

我试图在 9gag.com 上实现相同的效果,在屏幕上向下滚动多个侧边栏 div,I got the idea here .

当你滚动页面时,右边的 div 应该固定,直到到达左边的 div 的末尾,但由于某种原因,右边的 div 固定在页面的最顶部,我有 top(ad 和导航)div 设置为固定的所有时间。

最佳答案

如果我理解正确,那么发生的事情是意料之中的。 jQuery 插件 (scrollToFixed) 不知道您希望该元素位于另一个元素下方,因此您将不得不自己做。

最简单的方法是给#float-63(imo 不是一个很好的 ID)一个 margin-top 等于它应该位于下面的元素的高度。 70px 似乎工作正常。

问题是它会有 70px margin-top 即使它不是“固定”。插件修复后似乎没有向元素添加任何类型的类,但如果您了解 jQuery,添加应该很容易。

然后你可以简单地做 #float-63.scroll-to-fixed {margin-top: 70px}

关于javascript - jquery scrollToFixed 在到达页面顶部时停止,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13735479/

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