0

我愿意显示分为 2 类的可滚动列表。每个类别都有一个标题,我希望这些标题在我向下滚动列表时保持可见。

我知道有人问过类似的问题,并且我尝试过使用 scrollTop 但我无法让它在列表中工作。

任何帮助深表感谢。

4

2 回答 2

1

只需将要保留的元素的 CSS 位置设置为“固定”即可。

#fixedDiv{
position:fixed; 
} 
于 2012-11-20T17:18:08.197 回答
0

这是我过去使用的。它适用于<tag id="containerToFix"> 您可能需要使用的许多 VAR

var scrollLabel = false;
var scrollPadding = 40; //height from top of page
//use window.scroll NOT document.scroll for IE8, 7, 6
$(window).scroll(function () {

    var bottomScroll = $('.header').offset().top; //container of Tag above
    var maxScrolling = bottomScroll - (maxHeightOfContainerToFix) - (scrollPadding);//(scrollPadding) may not be needed for you
    var startScrolling = $('.ten').offset().top - scrollPadding;
    if ($(window).scrollTop() > startScrolling && $(window).scrollTop() < maxScrolling) {
        $('#containerToFix').css({ 'position': 'fixed', 'top': scrollPadding + 'px' });
        $('#containerToFix').addClass('ie7Fixed');
    }
    else if ($(window).scrollTop() < startScrolling) {
        $('#containerToFix').css({ 'position': '' });
    }
    else if ($(window).scrollTop() > maxScrolling) {
        scrollPosition = maxScrolling - $(window).scrollTop();
        $('#containerToFix').css({ 'top': scrollPosition + scrollPadding + 2 });
    };
});
于 2012-11-20T17:28:59.527 回答