加载的案例

<!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.touches0.clientY;

}

});

document.addEventListener("touchmove", function (e) {

if (touchStartY === null) {

return;

}

var touchMoveY = e.touches0.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>

相关推荐
龙井>_<3 分钟前
vsCode解决css代码补全不生效问题,UnoCSS插件失效修复
前端·css·ide·vscode
2501_9181269116 分钟前
一个上帝类程序作画
前端·css·css3
神明不懂浪漫34 分钟前
【第二章】HTML2——表格、表单标签
开发语言·经验分享·笔记·html
雨翼轻尘37 分钟前
01_HTML基本结构
前端·html·基本结构
木头羊oll1 小时前
Uniapp 与 H5 在 App 端的交互
前端·javascript·html
杨超越luckly1 小时前
Agent应用指南:利用GET请求获取赛力斯汽车门店位置信息
python·html·汽车·可视化·门店
杨超越luckly2 小时前
Agent应用指南:利用GET请求获取理想汽车门店位置信息
前端·python·html·汽车·可视化
卷帘依旧13 小时前
H5新特性
html
#麻辣小龙虾#13 小时前
小学三年级语文小游戏
css·html·css3
Agatha方艺璇14 小时前
前端开发技术复习笔记
vue·bootstrap·css3·html5·web