码迷,mamicode.com
首页 > 其他好文 > 详细

监听窗口大小改变,同时根据窗口大小修改某个元素的大小

时间:2018-11-14 22:35:50      阅读:192      评论:0      收藏:0      [点我收藏+]

标签:load   class   query   不能   res   jquer   onload   UNC   hresult   

jQuery的方法:

<script>  
    $(window).resize(function(){  
        var width = $(this).width();  
        var height = $(this).height();  
        alert(‘width’+width+’-height’+height);  
    });  
</script>    

 以上的方法,不能写在页面加载完成事件函数$(function(){})内部,而需要写在外面。

页面加载完成事件:

$(function(){});

$(document).ready(function(){});

window.onload = function(){};

我们项目中的代码:

// 监听窗口大小变化
function changeHeight(){
    let h = document.documentElement.clientHeight;
    document.getElementById("searchResult").style.height = h - 9 - 74 + ‘px‘;
    document.getElementById("goodsTableBody").style.height = h - 9 - 74 -160 + ‘px‘;
}
window.onload = function(){
    changeHeight();
};
window.onresize = function(){
    changeHeight();
};

 

监听窗口大小改变,同时根据窗口大小修改某个元素的大小

标签:load   class   query   不能   res   jquer   onload   UNC   hresult   

原文地址:https://www.cnblogs.com/zoeeying/p/9960242.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!