https://www.jiubbs.cn/s/js/tips.js
- // 从/tips.json 文件加载数据
- fetch('//www.jiubbs.cn/s/js/tips.json')
- .then(response => response.json()) // 解析为 JSON
- .then(data => {
- const randomTexts = data.tips; // 获取提示数组
- let currentIndex = 0; // 当前提示索引
-
- // 函数用于更新显示的提示
- const updateTip = () => {
- const selectedText = randomTexts[currentIndex];
- const randomTextElement = document.getElementById('random-text');
- // 更新提示文本
- randomTextElement.textContent = selectedText;
- randomTextElement.style.transform = 'translateY(0)'; // 初始化位置
- // 设置下一条提示
- currentIndex = (currentIndex + 1) % randomTexts.length;
- // 动画效果
- setTimeout(() => {
- randomTextElement.style.transform = 'translateY(-100%)'; // 向上移动
- }, 3000); // 3秒后开始移动
- // 循环调用更新提示
- setTimeout(updateTip, 4000); // 4秒后更新提示(3秒显示 + 1秒移动)
- };
- // 初始化提示
- updateTip();
- })
- .catch(error => {
- console.error('加载数据失败:', error);
- });
复制代码 |