Jquery if window.width()<780只适用于调整页面大小的情况.不;Don’我不总是打电话



我非常感谢您在这方面的帮助。当网站宽度变为780px时,我有两个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"));
    }

这只适用于我手动调整窗口大小的情况,有时也适用于android或ios手机。关于如何在加载窗口之前进行此insertAfter,有什么建议吗?谢谢

1st:无需在function listenWidth(e) {中通过e,只需使用function listenWidth() {

第二步:只运行功能

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

相关内容

最新更新