我正在尝试使用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的mediaqueries,因为width
和height
是插件的变量。
有什么想法吗?感谢
答案 0 :(得分: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";
}