2013-12-20 97 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> 
相关问题