【问题标题】:Reload particular div when rotates device旋转设备时重新加载特定的 div
【发布时间】:2019-04-19 06:36:52
【问题描述】:

我正在尝试创建一个函数,该函数在旋转设备时自动重新加载 div 中的内容(从平板电脑分辨率 -> 桌面分辨率,然后反向)。我尝试使用重新加载位置 url。它有效,但我只想将它应用于 div 元素,无需重新加载位置。

这是我的代码:

if (window.DeviceOrientationEvent) {
    if (window.innerHeight >= 1023 && window.innerWidth < 1023 || window.innerHeight < 1023 && window.innerWidth >= 1023) {
        window.addEventListener('orientationchange', function () {
        //location.reload();
    }
}

有人知道吗?谢谢大家阅读我的问题。

【问题讨论】:

    标签: javascript jquery orientation reload screen-rotation


    【解决方案1】:

    如果您使用的是 jquery,那么您可以执行类似的操作

    jQuery( window ).on( "orientationchange", function( event ) { ... } )
    

    更多信息

    https://api.jquerymobile.com/orientationchange/

    【讨论】:

      【解决方案2】:

      如果您的 div 的 id 为 blockA,您可以执行类似的操作

          function updateDiv(){ 
          $( "#blockA" ).load(window.location.href + " #blockA" );
          }
      

      【讨论】:

        【解决方案3】:

        只需重新加载 div 中的数据 - 不要使用 location.reload

        window.addEventListener("orientationchange", function(event) {
            div.innerHTML = "Reloaded"; //Reload the div here
        });
        

        【讨论】:

          猜你喜欢
          • 1970-01-01
          • 2018-01-05
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 2023-04-04
          相关资源
          最近更新 更多