【问题标题】:jQuery get the height from topjQuery从顶部获取高度
【发布时间】:2012-06-20 14:48:47
【问题描述】:

我需要获取从页面顶部到当前滚动条位置的高度并将其放置到我的链接:

<a class="poplight" rel="popup_name" href="#?w=here comes the value"></a>

我该怎么做?

【问题讨论】:

    标签: javascript jquery hyperlink height


    【解决方案1】:

    使用偏移量()

    $('.poplight').offset().top
    

    如果您需要滚动到该位置:

    $('html, body').animate({
        scrollTop: $('.poplight').offset().top
    }, 400);
    

    如果需要基于滚动的窗口顶部到当前位置的距离:

    $(window).scrollTop()
    

    想将它添加到 url:

    $(".poplight").attr("href", "#" + $(window).scrollTop())
    

    【讨论】:

    • 不,不。我必须把从网站顶部到当前视图的 px 高度。例如,您将网站滚动到一半,我需要从顶部到当前视图的高度并将其放到我的链接中。
    • 是的!而已。现在,如何将 px 中的 dintance 放到我的链接中?
    • 它没有将值放入我的链接中。这是网站:daniel-koczula.pl/testowy 我需要(例如到红色底部按钮)根据滚动链接放置从窗口顶部到当前位置的距离。当您悬停按钮时,您会看到daniel-koczula.pl/testowy/#?w=3200,我需要将值放在 w= 之后
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-09-07
    • 2015-12-24
    • 2018-03-31
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多