欢迎来到尧图网

客户服务 关于我们

您的位置:首页 > 文旅 > 旅游 > 加载的案例

加载的案例

2024/10/24 5:23:31 来源:https://blog.csdn.net/kuang_nu/article/details/141298473  浏览:    关键词:加载的案例

<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>下滑加载历史</title>
    <style>
      body {
        margin: 0;
        font-family: Arial, sans-serif;
      }

      #loadingContainer {
        display: none; /* 默认隐藏 */
        position: fixed;
        top: 0;
        left: 0;
        right: 0;
        background-color: white;
        text-align: center;
        padding: 10px;
        box-shadow: 0 2px 5px rgba(0, 0, 0, 0.1);
        z-index: 1000;
      }

      .spinner {
        display: inline-block;
        border: 4px solid rgba(0, 0, 0, 0.1);
        border-radius: 50%;
        border-top: 4px solid #333;
        width: 20px;
        height: 20px;
        animation: spin 1s linear infinite;
      }

      @keyframes spin {
        0% {
          transform: rotate(0deg);
        }
        100% {
          transform: rotate(360deg);
        }
      }

      .loadingText {
        display: inline-block;
        margin-left: 10px;
      }

      #content {
        text-align: center;
        padding: 20px;
        margin-top: 50px; /* 提供顶部空间 */
        font-size: 18px;
        color: #333;
      }
    </style>
  </head>
  <body>
    <div id="loadingContainer">
      <div class="spinner"></div>
      <div class="loadingText">加载中...</div>
    </div>
    <div id="content">
      ----------------下滑展示聊天记录---------------------
    </div>
    <script>
      var swipeUpTriggered = false;
      var touchStartY = null;
      var loadingContainer = document.getElementById("loadingContainer");

      document.addEventListener("touchstart", function (e) {
        if (window.scrollY === 0) {
          touchStartY = e.touches[0].clientY;
        }
      });

      document.addEventListener("touchmove", function (e) {
        if (touchStartY === null) {
          return;
        }

        var touchMoveY = e.touches[0].clientY;

        if (touchMoveY > touchStartY && !swipeUpTriggered) {
          loadingContainer.style.display = "block"; // 显示加载动画
          swipeUpTriggered = true;
        }
      });

      document.addEventListener("touchend", function (e) {
        if (swipeUpTriggered) {
          handleSwipeUp();
          swipeUpTriggered = false;
        }

        touchStartY = null;
      });

      function handleSwipeUp() {
        // 模拟数据加载过程
        setTimeout(function () {
          loadingContainer.style.display = "none"; // 隐藏加载动画
          // 这里可以添加加载数据的代码
        }, 2000); // 假设加载数据需要2秒
      }
    </script>
  </body>
</html>

版权声明:

本网仅为发布的内容提供存储空间,不对发表、转载的内容提供任何形式的保证。凡本网注明“来源:XXX网络”的作品,均转载自其它媒体,著作权归作者所有,商业转载请联系作者获得授权,非商业转载请注明出处。

我们尊重并感谢每一位作者,均已注明文章来源和作者。如因作品内容、版权或其它问题,请及时与我们联系,联系邮箱:809451989@qq.com,投稿邮箱:809451989@qq.com