Hidden div height (changing my advice)

后端 未结 4 1675
一向
一向 2021-01-02 15:54

Ok, I was going to answer someone\'s question here on SO about why their script wasn\'t working. They loaded content into a hidden div, then got the height so they could ani

4条回答
  •  小鲜肉
    小鲜肉 (楼主)
    2021-01-02 16:16

    I ran into the same problem with getting hidden element width, so I wrote this plugin call jQuery Actual to fix it. Instead of using

    $('#some-element').height();
    

    use

    $('#some-element').actual('height');
    

    will give you the right value for hidden element or element has a hidden parent.

    You can also use

    // get hidden element actaul width
    $( '.hidden' ).actual( 'width' );
    
    // get hidden element actaul innerWidth
    $( '.hidden' ).actual( 'innerWidth' );
    
    // get hidden element actaul outerWidth
    $( '.hidden' ).actual( 'outerWidth' );
    
    // get hidden element actaul height
    $( '.hidden' ).actual( 'height' );
    
    // get hidden element actaul innerHeight
    $( '.hidden' ).actual( 'innerHeight' );
    
    // get hidden element actaul outerHeight
    $( '.hidden' ).actual( 'outerHeight' );
    

    Full documentation please see here. There is also a demo include in the page.

    Hope this help :)

提交回复
热议问题