【问题标题】:Hide fixed content after scroll to specific position?滚动到特定位置后隐藏固定内容?
【发布时间】:2012-09-18 18:41:29
【问题描述】:

我使用这个 (https://github.com/cheald/floatingFixed) Javascript 在我的网站上创建社交分享栏。它工作得很好,但我不想在它滚动到页脚时显示它。这该怎么做?这是我网站的一个页面http://thedripple.com/1384/lg-optimus-g-launch-price/

【问题讨论】:

    标签: javascript css wordpress css-float jquery-events


    【解决方案1】:

    非常简单,因为您已经包含了 jQuery:

    $(window).scroll(function() { //when scrolled
        var flt = $(".floater");
        var offset = flt.offset().top + flt.height(); //get the current offset of the floater
        var footertop = $("#footer").offset().top; //and the footer's top offset
        if(offset > footertop) { //if you scrolled past the footer
            flt.hide(); //hide the sharing tab
        }
        else {
            flt.show(); //show it
        }
    });
    

    【讨论】:

    • 他可能希望将floater 的高度添加到窗口的 y 偏移量中。
    • 事实上,找到floater 的偏移量而不是窗口的y 偏移量可能会更好,因为它将包括任何其他定位(边距等)。
    猜你喜欢
    • 1970-01-01
    • 2017-11-19
    • 2011-09-25
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-07-06
    相关资源
    最近更新 更多