English 中文(简体)
复制j Query 美元(身体)
原标题:Replicating jQuery s $( body ).outerHeight(true) without jQuery
  • 时间:2012-04-13 15:42:08
  •  标签:
  • jquery

我有几页装上母体一页的单体,而我利用后天把儿童页的高度传给父母,这样就可以将子体重新定位。 儿童的网页非常简单,只有找到尸体的高度,才能让孩子们感到羞愧。 然而,迄今为止,我还没有能够把上述呼吁的影响复制到简明的 Java。

我尝试了在身体和身体上应用的加薪、抵减和客户工资的不同组合。 文件 内容,但没有对应。 而且,在不同的浏览器中,他们差别很大,特别是如果你在数量大不相同的儿童文件之间转用的话。 这里是所有儿童网页上载录器的实际代码:

window.onload = function() {
    alert("height(1) = " + document.body.scrollHeight + "
" +
        "height(2) = " + document.documentElement.scrollHeight + "
" +
        "height(3) = " + document.body.offsetHeight + "
" +
        "height(4) = " + document.documentElement.offsetHeight + "
" +
        "height(5) = " + document.body.clientHeight + "
" +
        "height(6) = " + document.documentElement.clientHeight + "
" +
        "height(7) = " + $( body ).outerHeight(true)
    );
    parent.postMessage($( body ).outerHeight(true) + "px", "*");
}

在每一种情况下,前六种数值中无七种(IE8/FF/Chrome)值。 第二种情况最接近,但在从一个大的儿童页转到一个较小的网页时,它却失败了——这仍然使前一页的篇幅大。

我确实读过了“ j”的渊源,但我的“ Java”言不好,不足以解决问题。

问题回答
$( body ).outerHeight(true) = document.body.height + document.body.marginTop + document.body.marginBottom + document.body.bordorTop + document.body.borderBottom

页: 1 那么, Qu子就开始运转,并开始理发。 反之,看上去看看看花时间试图去做什么似乎是毫无意义的;我只应该利用它。 我在括号中使用了这个词,因此所有浏览器都会把它放在任何一边。

Vanilla Masonry have a function - getWH() - refactored from Jquery which should do what you need: https://github.com/desandro/vanilla-masonry

// returns width/height of element, refactored getWH from jQuery
function getWH( elem, measure, isOuter ) {
    // Start with offset property
    var isWidth = measure !==  height ,
        val = isWidth ? elem.offsetWidth : elem.offsetHeight,
        dirA = isWidth ?  Left  :  Top ,
        dirB = isWidth ?  Right  :  Bottom ,
        computedStyle = getStyle( elem ),
        paddingA = parseFloat( computedStyle[  padding  + dirA ] ) || 0,
        paddingB = parseFloat( computedStyle[  padding  + dirB ] ) || 0,
        borderA = parseFloat( computedStyle[  border  + dirA +  Width  ] ) || 0,
        borderB = parseFloat( computedStyle[  border  + dirB +  Width  ] ) || 0,
        computedMarginA = computedStyle[  margin  + dirA ],
        computedMarginB = computedStyle[  margin  + dirB ],
        marginA, marginB;

    if ( !supportsPercentMargin ) {
        computedMarginA = hackPercentMargin( elem, computedStyle, computedMarginA );
        computedMarginB = hackPercentMargin( elem, computedStyle, computedMarginB );
    }

    marginA = parseFloat( computedMarginA ) || 0;
    marginB = parseFloat( computedMarginB ) || 0;

    if ( val > 0 ) {

        if ( isOuter ) {
            // outerWidth, outerHeight, add margin
            val += marginA + marginB;
        } else {
            // like getting width() or height(), no padding or border
            val -= paddingA + paddingB + borderA + borderB;
        }

    } else {

        // Fall back to computed then uncomputed css if necessary
        val = computedStyle[ measure ];
        if ( val < 0 || val === null ) {
            val = elem.style[ measure ] || 0;
        }
        // Normalize "", auto, and prepare for extra
        val = parseFloat( val ) || 0;

        if ( isOuter ) {
            // Add padding, border, margin
            val += paddingA + paddingB + marginA + marginB + borderA + borderB;
        }
    }

    return val;
}

[edit] 您还需要 gr洗黑板,并从面包车-马森里获得苯。 j)





相关问题
getGridParam is not a function

The HTML: <a href="javascript:void(0)" id="m1">Get Selected id s</a> The Function: jQuery("#m1").click( function() { var s; s = jQuery("#list4").getGridParam( selarrrow )...

selected text in iframe

How to get a selected text inside a iframe. I my page i m having a iframe which is editable true. So how can i get the selected text in that iframe.

jQuery cycle page with links

I am using the cycle plugin with pager functionality like this : $j( #homebox ) .cycle({ fx: fade , speed: fast , timeout: 9000, pager: #home-thumbs , ...

jquery ui dialog opens only once

I have a button that opens a dialog when clicked. The dialog displays a div that was hidden After I close the dialog by clicking the X icon, the dialog can t be opened again.

jConfirm with this existing code

I need help to use jConfirm with this existing code (php & Jquery & jAlert). function logout() { if (confirm("Do you really want to logout?")) window.location.href = "logout.php"; } ...

Wrap text after particular symbol with jQuery

What I m trying to do, is wrap text into div inside ll tag. It wouldn t be a problem, but I need to wrap text that appears particularly after "-" (minus) including "minus" itself. This is my html: &...

热门标签