首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >在javascript中设置vars图像的高度和宽度

在javascript中设置vars图像的高度和宽度
EN

Stack Overflow用户
提问于 2016-03-03 11:06:49
回答 1查看 74关注 0票数 0

我试图制作一个图像作为我的背景,并符合浏览器的尺寸。然而,我明白了:expmrt.html:15 Uncaught TypeError: Cannot set property 'width' of null

代码语言:javascript
复制
//Get the browser legth and height, then after the code is done, time out in 300 miliseconds.
function ScreenLoop() {
  var Width = window.innerWidth;
  var Height = window.innerHeight;
  alert("Width: " + Width + " and also Height: " + Height) //Debugging reasons
  document.getElementById("theimage").width = Width; // Where the error: expmrt.html:15 Uncaught TypeError: Cannot set property 'width' of null) occures for some reason.
  document.getElementById("theimage").height = Height;
  setTimeout(ScreenLoop(), 300);
};
ScreenLoop();
代码语言:javascript
复制
<img src="tl2fZkc.png" id="theimage" width="50" height="50" alt="theimage" />

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2016-03-03 11:12:05

从窗口调用load事件中的ScreenLoop()

代码语言:javascript
复制
window.onload = function() {
   ScreenLoop();
}
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/35770479

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档