javascript - How to dynamically adjust page height to its content? -


i'm working on website iframe. iframe doesn't have scrollbars.

in iframe there elements, slide open when click them. problem if slide 1 open, bigger iframe height, stuck there, can't scroll.

so want height of iframe synchronises height of content.

this jquery code slide 1 element open, fits content:

$( "#effect1" ).animate({     height: $( "#effect2" ).prop( "scrollheight" ) }, 1000 ); $( "#effect2" ).animate({     height: $( "#effect2" ).prop( "scrollheight" ) - parseint( $( "#effect2" ).css( "padding-top" ), 10 ) - parseint( $( "#effect2" ).css( "padding-bottom" ), 10 ) }, 1000 ); 

so guess add changing of iframe's height after that.

what i've tried far:

i took code this website dealing same problem.

function getdocheight(doc) {     doc = doc || document;     // stackoverflow.com/questions/1145850/     var body = doc.body, html = doc.documentelement;     var height = math.max( body.scrollheight, body.offsetheight,          html.clientheight, html.scrollheight, html.offsetheight );     return height; }  function setiframeheight(id) {     var ifrm = document.getelementbyid(id);     var doc = ifrm.contentdocument? ifrm.contentdocument:          ifrm.contentwindow.document;     ifrm.style.visibility = 'hidden';     ifrm.style.height = "10px"; // reset minimal height ...     // ie opt. bing/msn needs bit added or scrollbar appears     ifrm.style.height = getdocheight( doc ) + 4 + "px";     ifrm.style.visibility = 'visible'; } 

so after sliding of 1 iframe's element call setiframeheight("iframe");. there 2 problems:

  • it feels bit ticky, height switches 1 moment another
  • instead of increasing iframe's height, increases document's height

so how can dynamically adjust iframe's height?

i have tried many options. no option best. can try way :

  • in iframe, create interval function (setinterval) run each mili time check document/element height changes. if changed, call parent window , pass new height value , fit iframe window height.

Comments

Popular posts from this blog

c++ - Difference between pre and post decrement in recursive function argument -

php - Nothing but 'run(); ' when browsing to my local project, how do I fix this? -

php - How can I echo out this array? -