Jquery if window.width()<780 仅在我调整页面大小时有效。不能一直在 phone 上工作

Jquery if window.width()<780 only works when I resize the page. Doesn't work on phone all the time

非常感谢您对此的帮助。 当网站宽度变为 780px 时,我有 2 个 div 需要改变位置。 我有以下代码。

jQuery(document).ready(jQuery(window).bind("resize", listenWidth));

function listenWidth(e) {
    if (jQuery(window).width() < 780) {
      jQuery("#pgc-107-1-0").remove().insertAfter(jQuery("#pgc-107-1-1"));
    } else {

      jQuery("#pgc-107-1-0").remove().insertBefore(jQuery("#pgc-107-1-1"));


    }

这仅在我手动调整 window 大小时有效,有时在手机 android 或 ios 上有效。关于如何在 window 加载之前制作此 insertAfter 的任何建议? 谢谢

1st: 无需在 function listenWidth(e) { 中传递 e 只需使用 function listenWidth() {

2nd: 只是 运行 函数

jQuery(document).ready(function(){
  listenWidth();  //<<<<<<<
  jQuery(window).on("resize", listenWidth)); // i used .on()  instead of .bind()
});