【发布时间】:2013-04-06 23:13:20
【问题描述】:
我希望 div 类“内容”的大小根据用户屏幕分辨率的大小而变化。
到目前为止,我已经编写了这个 javascript
function resize()
{
if ((screen.width>1024)) { $(".content").style.width = 560 + "px"; $(".content").style.height = 315 + "px" }
if ((screen.width>1280)) { $(".content").style.width = 640 + "px"; $(".content").style.height = 360 + "px" }
else { $(".content").style.width = 853 + "px"; $(".content").style.height = 480 + "px" }
};
显然在 html 中我有类 '.content'
为什么这段代码不起作用?
【问题讨论】:
-
您最好查看浏览器大小,而不是屏幕分辨率。无论我的屏幕大小如何,您的内容不应该响应我的浏览器大小吗?我没有让我的浏览器全屏显示。
-
你为什么不使用媒体查询?
-
目前我的编码水平很差。现在我会研究媒体查询...