我目前正在爲我的網站編寫一個新主題,並且遇到了動態調整iframe中div元素高度的問題。 iframe中的源代碼位於我的域中,但無法直接編輯它。在iframe中訪問和調整div的高度
我想要做的是有一個腳本,它將讀取iframe的高度(例如1000px),讀取iframe中兩個div的高度(例如#content height = 200px和#question height = 600px )。然後調整這兩個高度以適合iframe頁面。
,所以我想的東西,將是這樣的:
var height = $('iframe').height();
var content_height = $('iframe').contents().find('#content').height();
var question_height = $('iframe').contents().find('#question').height();
var diff = height - content_height - question_height
if diff > 0
"new content height" = content_height + diff/2
"new question height" = content_question + diff/2
end
我是一個完整的noob當涉及到JavaScript,因此任何幫助將是巨大的。
給iframe和div一個ID ..並使用yourid.height()... – bipen
您正在使用jQuery?然後你可以做到這一點,它只是選擇器和'height()'方法。嘗試一下! – Bergi
剛纔我會說一說。感謝您的快速回復。 – lwm