jQuery externalHeight用于隐藏元素

jQuery externalHeight用于隐藏元素

问题描述:

我在获取列表项的外部高度时遇到问题-与以下帖子类似: jQuery:获取jQuery中隐藏元​​素的高度

I am having a problem with getting the outer height of a list item - similar to the below post: jQuery: Get height of hidden element in jQuery

这是我的代码:

function tabload() {
    $('.tab li:first-child').addClass('selected');

    $(".tab ul").css({ 'position': 'absolute', 'visibility': 'hidden', 'display': 'block'});

    var h = $(".tab ul").outerHeight(true);

    $(".tab ul").css("height", h);

    $(".tab ul").css({'position': 'relative', 'visibility': 'visible', 'display': 'none' });
};

我做错什么了吗?

由于在stackoverflow上还有其他一些类似的问题,因此我之前已经在博客中介绍了此问题.看一下博客文章

I have blogged about this issue before since there are a few other similar questions here on stackoverflow. Take a look at the code in this blog post

我最初只是为width方法开发的,但是根据注释,代码已发展为包括内部/外部尺寸.

I initially developed it just for the width method, but based on comments the code has evolved to include inner/outer dimensions.