我已经查看了有关此主题的许多问题,但似乎无法找出我的代码有什么问题。任何帮助将不胜感激!
$(window).resize(function(){
var newwidth = $(window).innerWidth();
var newheight = $(window).innerHeight();
$("#element").height(newheight).width(newwidth);
});
如果调整窗口大小,我正在尝试将 #element 的大小调整为与窗口相同的高度和宽度。
About .innerWidth()
, from docs http://api.jquery.com/innerWidth/:
该方法不适用于窗口和文档对象;为了
这些,请使用 .width() 代替。
有一样的note http://api.jquery.com/innerHeight/ for .innerHeight()
also.
所以你需要使用.width()
and .height()
:
$(window).resize(function(){
var newwidth = $(window).width();
var newheight = $(window).height();
$("#element").height(newheight).width(newwidth);
});
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)