小编h0t*_*1r3的帖子

根据屏幕res更改javascript中的CSS类高度和宽度

我希望div类'content'的大小根据用户屏幕分辨率的大小而改变.

到目前为止我写了这个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" }
};
Run Code Online (Sandbox Code Playgroud)

显然在html中我有类'.content'

为什么这段代码不起作用?

jquery screen-resolution

4
推荐指数
1
解决办法
3万
查看次数

标签 统计

jquery ×1

screen-resolution ×1