0

我正在尝试使用 jQuery 进行媒体查询,但无法正常工作。

    if ((screen.width>=20) || (screen.width<300)){
        width="190"; //Adjust the width of the image
        height="170"; //Adjust the height of the image
    }
    if ((screen.width>=300) || (screen.width<350)){
        width="240"; height="200";
    }
    if ((screen.width>=351) || (screen.width<400)){
        width="280"; height="220";
    }
    if ((screen.width>=401) || (screen.width<599)){
        width="320"; height="240";
    }
    if ((screen.width>=600) || (screen.width<757)){
        width="440";  height="320";
    }
    if ((screen.width>=758) || (screen.width<899)){
        width="320"; height="240";
    }

加载插件时调用代码,因为添加了新内容。这是一个单页应用程序。无需刷新浏览器即可加载内容。我需要将媒体查询与 jquery 一起使用,因为widthheight是插件的变量。

任何想法?谢谢

4

1 回答 1

1

这是你想要的吗?

    if ((window.innerWidth>=20) || (window.innerWidth<300)){
        width="190"; //Adjust the width of the image
        height="170"; //Adjust the height of the image
    }
    if ((window.innerWidth>=300) || (window.innerWidth<350)){
        width="240"; height="200";
    }
    if ((window.innerWidth>=351) || (window.innerWidth<400)){
        width="280"; height="220";
    }
    if ((window.innerWidth>=401) || (window.innerWidth<599)){
        width="320"; height="240";
    }
    if ((window.innerWidth>=600) || (window.innerWidth<757)){
        width="440";  height="320";
    }
    if ((window.innerWidth>=758) || (window.innerWidth<899)){
        width="320"; height="240";
    }
于 2013-01-16T20:56:04.627 回答