javascript - How to get the height of the displayed part of an element in js?
过去多啦不再A梦
过去多啦不再A梦 2017-06-12 09:30:22
0
4
738

When an element is scrolled, some or even all elements will be hidden. How to get the height of the visible part? Using clientHeight doesn't work, what should I do?

过去多啦不再A梦
过去多啦不再A梦

reply all(4)
某草草

Do you mean the staircase effect? ​​You can see the scrolling distance in the title


$(document).ready(function(){
$(window).scroll(function(){

    // 获得窗口滚动上去的距离
    var ling = $(document).scrollTop();
    // 在标题栏显示滚动的距离,不需要注释掉
    document.title = ling;
    // 如果滚动距离大于660的时候让楼梯显示
    if(ling>660){
        $('.return_top').show();
    }
}

phpcn_u1582

Use offsetHeight

typecho

Is it true that the clientHeight is not set for the parent container, the client is set for the visible area, the offset is set for the visible area with the scroll bar, and the scroll is set for the complete area

Here is an example for preview

给我你的怀抱

clientHeight

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template