点击查看html编辑器说明文档

天体运动edit icon

|
|
Fork(复制)
|
|
作者:
柳峰

👉 新版编辑器已上线,点击进行体验吧!

BUG反馈
嵌入
设置
下载
HTML
格式化
支持Emmet,输入 p 后按 Tab键试试吧!
<head> ...
展开
</head>
<body>
            
            <!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <title>天体运动演示</title>
    <style>
        body {
            margin: 0;
            height: 100vh;
            display: flex;
            justify-content: center;
            align-items: center;
            background: linear-gradient(to bottom, #000428, #004e92);
            overflow: hidden;
            font-family: Arial, sans-serif;
        }

        .container {
            position: relative;
            width: 800px;
            height: 600px;
        }

        #sun {
            position: absolute;
            left: 50%;
            top: 50%;
            width: 80px;
            height: 80px;
            background: radial-gradient(#ffd700, #ff8c00);
            border-radius: 50%;
            transform: translate(-50%, -50%);
            box-shadow: 0 0 50px #ff8c00;
        }

        .earth-orbit {
            position: absolute;
            left: 50%;
            top: 50%;
            width: 400px;
            height: 400px;
            border: 1px dashed rgba(255, 255, 255, 0.3);
            border-radius: 50%;
            transform: translate(-50%, -50%);
            animation: rotate 20s linear infinite;
        }

        #earth {
            position: absolute;
            left: 0;
            top: -20px;
            width: 40px;
            height: 40px;
            background: radial-gradient(#2193b0, #2193b0);
            border-radius: 50%;
            cursor: pointer;
        }

        .moon-orbit {
            position: absolute;
            width: 100px;
            height: 100px;
            border: 1px dashed rgba(255, 255, 255, 0.2);
            border-radius: 50%;
            top: 50%;
            left: 50%;
            transform: translate(-50%, -50%);
        }

        #moon {
            position: absolute;
            left: 0;
            top: -8px;
            width: 16px;
            height: 16px;
            background: radial-gradient(#d3d3d3, #808080);
            border-radius: 50%;
        }

        .controls {
            position: absolute;
            bottom: 20px;
            left: 50%;
            transform: translateX(-50%);
            display: flex;
            gap: 15px;
        }

        button {
            padding: 10px 20px;
            background: rgba(255, 255, 255, 0.1);
            border: 1px solid rgba(255, 255, 255, 0.3);
            color: white;
            border-radius: 5px;
            cursor: pointer;
            transition: all 0.3s;
        }

        button:hover {
            background: rgba(255, 255, 255, 0.2);
        }

        .info {
            position: absolute;
            top: 20px;
            left: 50%;
            transform: translateX(-50%);
            color: white;
            text-align: center;
        }

        @keyframes rotate {
            from { transform: translate(-50%, -50%) rotate(0deg); }
            to { transform: translate(-50%, -50%) rotate(360deg); }
        }
    </style>
</head>
<body>
    <div class="container">
        <div class="info">
            <h2>太阳-地球-月亮系统演示</h2>
            <p id="date">当前时间:</p>
        </div>
        <div id="sun"></div>
        <div class="earth-orbit">
            <div id="earth">
                <div class="moon-orbit">
                    <div id="moon"></div>
                </div>
            </div>
        </div>
        <div class="controls">
            <button onclick="toggleAnimation()" id="toggleBtn">开始</button>
            <button onclick="resetAnimation()">重置</button>
        </div>
    </div>

    <script>
        let isAnimating = false;
        const earthOrbit = document.querySelector('.earth-orbit');
        const moonOrbit = document.querySelector('.moon-orbit');
        const toggleBtn = document.getElementById('toggleBtn');
        const dateElement = document.getElementById('date');

        function toggleAnimation() {
            isAnimating = !isAnimating;
            toggleBtn.textContent = isAnimating ? '暂停' : '开始';
            earthOrbit.style.animationPlayState = isAnimating ? 'running' : 'paused';
            moonOrbit.style.animationPlayState = isAnimating ? 'running' : 'paused';
        }

        function resetAnimation() {
            earthOrbit.style.animation = 'none';
            moonOrbit.style.animation = 'none';
            setTimeout(() => {
                earthOrbit.style.animation = 'rotate 20s linear infinite';
                moonOrbit.style.animation = 'rotate 5s linear infinite';
                if(isAnimating) earthOrbit.style.animationPlayState = 'running';
            }, 10);
        }

        // 更新时间显示
        function updateDateTime() {
            const now = new Date();
            dateElement.textContent = `当前时间:${now.toLocaleString()}`;
        }
        setInterval(updateDateTime, 1000);

        // 初始化月球轨道动画
        moonOrbit.style.animation = 'rotate 5s linear infinite';
    </script>
</body>
</html>
        
编辑器加载中
</body>
CSS
格式化
            
            /* 示例代码 */
body {
  text-align: center;
}
i {
  color: #777;
}

        
编辑器加载中
JS
格式化
            
            // 示例代码
console.log(["Hello 笔.COOL 控制台"])
        
编辑器加载中
预览
控制台
清空