北京時(shí)間網(wǎng)頁秒顯示浮窗 北京時(shí)間校準(zhǔn)浮窗
Bukalapak印尼優(yōu)選賣家服務(wù)2025-06-232910
要實(shí)現(xiàn)北京時(shí)間網(wǎng)頁秒顯示浮窗,可以使用JavaScript和CSS。以下是一個(gè)簡(jiǎn)單的示例:
- 創(chuàng)建一個(gè)HTML文件,例如
index.html
,并添加以下內(nèi)容:
<!DOCTYPE html>
<html lang="zh">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>北京時(shí)間浮窗</title>
<style>
#floating-window {
position: fixed;
top: 50%;
left: 50%;
transform: translate(-50%, -50%);
padding: 20px;
background-color: #fff;
box-shadow: 0 0 10px rgba(0, 0, 0, 0.3);
z-index: 9999;
}
</style>
</head>
<body>
<div id="floating-window">
<h1>北京時(shí)間</h1>
<p>當(dāng)前時(shí)間:2022年1月1日 14:55:46</p>
</div>
<script src="main.js"></script>
</body>
</html>
- 然后,創(chuàng)建一個(gè)名為
main.js
的JavaScript文件,并添加以下內(nèi)容:
// 獲取北京時(shí)間元素
const timeElement = document.getElementById('floating-window h1');
// 設(shè)置北京時(shí)間
timeElement.textContent = '當(dāng)前時(shí)間:2022年1月1日 14:55:46';
// 監(jiān)聽窗口大小變化事件,實(shí)現(xiàn)秒顯示浮窗
window.addEventListener('resize', () => {
setTimeout(() => {
timeElement.textContent = '當(dāng)前時(shí)間:2022年1月1日 14:55:46';
}, 1000);
});
這個(gè)示例中,我們創(chuàng)建了一個(gè)包含北京時(shí)間的浮窗,并使用JavaScript監(jiān)聽窗口大小變化事件,每秒更新北京時(shí)間。
本文內(nèi)容根據(jù)網(wǎng)絡(luò)資料整理,出于傳遞更多信息之目的,不代表金鑰匙跨境贊同其觀點(diǎn)和立場(chǎng)。
轉(zhuǎn)載請(qǐng)注明,如有侵權(quán),聯(lián)系刪除。