[jQuery] 自動增減 iframe 佔用版面高度 Grow & shrink the height of iframe automatically

筆記一下目前這不很優但至少能動的解。(幾無 JavaScript 經驗的我… Orz)

$(document).ready( function() {
  $('body').mousemove( function(e) {
    var document_height = $('#embed-iframe').contents().find('body').attr('offsetHeight');
    $('#embed-iframe').height(document_height + 32);

適用場合:被拿來嵌入當成主要網頁內容的 iframe,其佔用版面高度未知(動態增減之類)的情況。(更白話一點講,就是把 iframe 當 frame 用。)

CC BY-SA 4.0 This work is licensed under a Creative Commons Attribution-ShareAlike 4.0 International License.

Leave a Reply

Your email address will not be published. Required fields are marked *