2013-12-20 29 views
0

我沒有太多經驗jQuery當窗口大小發生變化時動態設置<frameset>行

當瀏覽器窗口改變時,我需要動態地設置rows屬性<frameset>

這裏是我的框架:<FRAMESET BORDER='0' ROWS="112,*" id='reSizeWindow'>

而jQuery的,我使用的是:

$('#reSizeWindow').css('rows', $(window).height()+50+'px'); 

這沒有工作,所以我用:

<script> 
window.onresize = function() { 
    var widthViewport = window.innerWidth || document.body.clientWidth; 
    var el = document.getElementById('reSizeWindow'); 
    if(widthViewport < 1000) { 
     el.setAttribute(); 
     el.rows = '108' 
    } else { 
     el.rows = '100%'; 
    } 
}; 
</script> 

在這裏,我得到的錯誤as:

el is NULL

請幫我弄一個工作的JavaScript/jQuery的

回答

1

試試這個

$(document).ready(function() { 
$(window).on('resize', function(){ 
     var win = $(this); //this = window 
     if (win.height() <= 1000) 
     { 
      parent.document.getElementsByTagName('frameset')[ 0 ].rows = '108,*' 
     } 
     else { parent.document.getElementsByTagName('frameset')[ 0 ].rows = '150,*' } 
});​​​​ 
});​​​​ 
+0

不工作。 :( –

+0

你應該在你的文件中有jQuery庫 –

+0

我有'jquery-1.8.0.min.js'。 –

1

下面的代碼爲我工作用的Sridhar R幫助。

<script type="text/javascript" language="javascript"> 
$(document).ready(function() { 
    $(window).on('resize', function(){ 
     var win = $(this); 
     if (win.width() <= 1000) { // width() and not height() 
      parent.document.getElementsByTagName('frameset')[ 0 ].rows = '150,*'; 
     } else { 
      parent.document.getElementsByTagName('frameset')[ 0 ].rows = '108,*'; 
     } 
    }); 
}); 
</script> 
相關問題