English 中文(简体)
我如何 gr笑装满的 content子的高度?
原标题:How do I grab the height of an ajax loaded content?

在我的网页上,装满部分内容。 在这一装满的四舍五入体内,我有一个子端,在装满的部件中装载额外内容。 迄今为止,这项工作是完美的。

但是,在装满后,我想把包装的高度(除鞋子外,这整整整页),但不知道我的工作如何只产生第一点内容的高度。 我如何提升新装货内容?

这是我的职责:

$(function(){

        var 
        $subContent = $(".subcontent"),
        $subWrap    = $(".maincontent"),
        $newWrap    = $("#wrapper"),
        subHeight   = 0,
        $el;

        $newWrap.height($newWrap.height());
        subHeight = $newWrap.height() - $subContent.height();

        $("ul.linkbox li a").live( click , function (e) {
    newLink = $(this).attr("href");
        e.preventDefault();

    $(".textbox").find(".subcontent").fadeTo(200,0, function() {

    $(".textbox").load(newLink +  " .subcontent" , function() {

    $(".subcontent").fadeTo(200,1, function() {

        $newWrap.animate({height: subHeight + $subContent.height() + "px"});

    }); 
    }); 
    });   
        });

});
最佳回答

您在作出任何估计之前计算出的分数。

subHeight = $newWrap.height() - $subContent.height();

之后,在对贵方进行某种估计之后,就使用了这一说法。

 $newWrap.animate({height: subHeight + $subContent.height() + "px"});

This may affect your code behavior. I would suggest recalculate the subHeight again when you need it:

$newWrap.animate({height: $newWrap.height() - $subContent.height() + $subContent.height() + "px"});
问题回答

回答问题:

我刚才补充了以下法典,使之现在能够发挥作用:

$("#wrapper").css("height","auto");

如果我不理解你的话,你正试图达到高含量,而这种高含量正来自亚克斯的反应。 我知道的第一种方式是<代码>$(#objectId ).attr(高)。

var heightOfSubContentn = $(".textbox").find(".subcontent").attr("height")

In my experience the only way to reliably get the height is to create (either on page load or on the fly while the ajax is executing) some container that you position out of the users view via css:

#stage {
  /* hide the container while maintaining ability to render content */
  visibility: hidden;
  opacity:0;

  /* position out of view of user */
  position: absolute;
  z-index: -1;

  top: -9999em;
  left: -9999em;
}

Note: If your area that you are loading your ajax content into has a set width make sure to apply this width to the #stage element too otherwise the rendered content won t be the correct height.

If this is a one-off use case then you can of course hard code the width in the css or alternative you can set the width on the click event that fires the ajax load based on the content area.

下面是你现在如何安排麻风气负荷的一个例子:

// We re assuming that the content area is #area
// and that the out-of-view stage is #stage
// .myTrigger can be anything really, probably a link that get s the new content via an href.

$( .myTrigger ).click(function(event) {
    var stage = $( #stage ),
         area    = $( #area );

    // get the width of the destination and set this to be the width of your stage container.
    stage.width( area.width() );

    // fire the ajax request
    $.ajax({
       url:  whatevertheURLis ,
       type:  GET ,
       dataType:  html ,
       complete: function (xhr, textStatus) {
          var ajaxContent = $(xhr.responseText);
            var newHeight = stage.append( ajaxContent ).getHeight(); // this will be a number

            // we re now setting the new height onto our content area element and then inject the ajax content.
            // the area.height(newHeight) could equally be an animate statement with the html(ajaxContent) being run in its callback.
            area.height( newHeight ).html( ajaxContent );
       }
    });


});

// helper function to get the height quickly from the stage element.
$.fn.getHeight = function() {
    var stage = $( #stage );
    // store content height.
    var stageHeight = stage.height(); 

    // remove the temporary content.
    stage.children().remove();

    // return the height.
    return stageHeight;
};

希望这一帮助。





相关问题
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: &...

热门标签