我现在正在建立一个 wordpress 网站,我想根据浏览器的宽度制作 2 个单独的 do_shortcode("[]"),并在浏览器宽度发生变化时刷新和更改内容。有没有办法做到这一点?我通过阅读其他关于 PHP/Javascript 的线程的理解是,由于 PHP 在 JS 之前运行,因此两者不能很好地相互交互。有没有最好的方法来做到这一点?
谢谢你的帮助!
我现在正在建立一个 wordpress 网站,我想根据浏览器的宽度制作 2 个单独的 do_shortcode("[]"),并在浏览器宽度发生变化时刷新和更改内容。有没有办法做到这一点?我通过阅读其他关于 PHP/Javascript 的线程的理解是,由于 PHP 在 JS 之前运行,因此两者不能很好地相互交互。有没有最好的方法来做到这一点?
谢谢你的帮助!
如果您想更改站点的布局,例如:如果 browser-min-width = 960px 将背景颜色更改为红色,
如果 browser-max-width = 960px 将背景更改为绿色。
如果您想要这样的东西,只需将以下内容放入您的css 文件中:
@media only screen and (min-width:960px){
//DO something
}
@media only screen and (max-width:768px){
//DO something
}
@media only screen and (min-width:768px) and (max-width:960px){
//DO something
}
如果您想在 javascript 中执行此操作,请使用以下代码:
if (window.matchMedia('only screen and (max-width: 960px)').matches) {
//DO something
}
if(window.matchMedia('only screen and (min-width: 768px) and (max-width: 960px)').matches) {
//DO something
}
我希望这有帮助。抱歉,如果我误解了您的问题,这不是您要寻找的答案。