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(); };
如对本文有疑问, 点击进行留言回复!!
使用纯前端JavaScript实现Excel导入导出方法过程详解
微信小程序完美解决scroll-view高度自适应问题的方法
bootstrap-closable-tab可实现关闭的tab标签页插件
vue-cli单页面预渲染seo-prerender-spa-plugin操作
网友评论