search

Home  >  Q&A  >  body text

javascript - How to get the height of the displayed part of an element in js?

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梦2766 days ago752

reply all(4)I'll reply

  • 某草草

    某草草2017-06-12 09:32:22

    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();
        }
    }
    
    

    reply
    0
  • phpcn_u1582

    phpcn_u15822017-06-12 09:32:22

    Use offsetHeight

    reply
    0
  • typecho

    typecho2017-06-12 09:32:22

    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

    reply
    0
  • 给我你的怀抱

    给我你的怀抱2017-06-12 09:32:22

    clientHeight

    reply
    0
  • Cancelreply