0
我有一個id爲「myframe」的iframe我想在設備旋轉時更改高度。這是這樣的設備旋轉時如何更改iframe的大小?
<script>
$(document).on("pagecreate",function(event){
$(window).on("orientationchange",function(){
if(window.orientation == 0)
{
document.getElementById("myframe").height = 300;
}
else
{
document.getElementById("myframe").height = 500;
}
});
});
</script>
,但是需要這樣
<script>
$(document).on("pagecreate",function(event){
$(window).on("orientationchange",function(){
if(window.orientation == 0)
{
var oldh = document.getElementById("myframe").height;
var newh = parseInt(oldh) * 1.4;
if(newh != ''){
document.getElementById("myframe").height = newh;
}
}
else
{
var oldh = document.getElementById("myframe").height;
var newh = parseInt(oldh)/1.4;
if(newh != ''){
document.getElementById("myframe").height = newh;
}
}
});
});
</script>
工作,如果我打印的VAR newh它正確返回結果,但仍然無法運行我的功能
你試過用css設置高度嗎? 'document.getElementById('myframe')。style.height = newh +'px';' –
此外,您的計算可能會導致浮點數。你要做這樣的:'VAR newh = parseInt函數(oldh/1.4);' –
你說得對有關parseInt函數格式它工作得很好。謝謝:)如果你把它作爲一個答案,我將迎來它正確。 – Nato