HTML實戰:愛心圖的實現

設計思路

  • 使用純CSS創建多種風格的愛心

  • 添加平滑的動畫效果

  • 實現交互式愛心生成器

  • 響應式設計適應不同設備

  • 優雅的UI布局和色彩方案

  • <!DOCTYPE html>
    <html lang="zh-CN">
    <head>
    ? ? <meta charset="UTF-8">
    ? ? <meta name="viewport" content="width=device-width, initial-scale=1.0">
    ? ? <title>HTML愛心圖實戰</title>
    ? ? <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.4.0/css/all.min.css">
    ? ? <style>
    ? ? ? ? * {
    ? ? ? ? ? ? margin: 0;
    ? ? ? ? ? ? padding: 0;
    ? ? ? ? ? ? box-sizing: border-box;
    ? ? ? ? ? ? font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
    ? ? ? ? }
    ? ? ? ??
    ? ? ? ? body {
    ? ? ? ? ? ? background: linear-gradient(135deg, #ffafbd, #ffc3a0);
    ? ? ? ? ? ? color: #5a2a2a;
    ? ? ? ? ? ? min-height: 100vh;
    ? ? ? ? ? ? padding: 20px;
    ? ? ? ? ? ? display: flex;
    ? ? ? ? ? ? flex-direction: column;
    ? ? ? ? ? ? align-items: center;
    ? ? ? ? }
    ? ? ? ??
    ? ? ? ? header {
    ? ? ? ? ? ? text-align: center;
    ? ? ? ? ? ? padding: 30px 0;
    ? ? ? ? ? ? width: 100%;
    ? ? ? ? ? ? max-width: 1200px;
    ? ? ? ? }
    ? ? ? ??
    ? ? ? ? h1 {
    ? ? ? ? ? ? font-size: 2.8rem;
    ? ? ? ? ? ? margin-bottom: 10px;
    ? ? ? ? ? ? text-shadow: 2px 2px 4px rgba(0,0,0,0.1);
    ? ? ? ? ? ? color: #7a1f1f;
    ? ? ? ? ? ? position: relative;
    ? ? ? ? ? ? display: inline-block;
    ? ? ? ? }
    ? ? ? ??
    ? ? ? ? h1::after {
    ? ? ? ? ? ? content: "";
    ? ? ? ? ? ? position: absolute;
    ? ? ? ? ? ? bottom: -10px;
    ? ? ? ? ? ? left: 50%;
    ? ? ? ? ? ? transform: translateX(-50%);
    ? ? ? ? ? ? width: 120px;
    ? ? ? ? ? ? height: 4px;
    ? ? ? ? ? ? background: linear-gradient(90deg, transparent, #ff5e7d, transparent);
    ? ? ? ? ? ? border-radius: 2px;
    ? ? ? ? }
    ? ? ? ??
    ? ? ? ? .subtitle {
    ? ? ? ? ? ? font-size: 1.2rem;
    ? ? ? ? ? ? max-width: 700px;
    ? ? ? ? ? ? margin: 20px auto;
    ? ? ? ? ? ? line-height: 1.6;
    ? ? ? ? ? ? color: #5a2a2a;
    ? ? ? ? }
    ? ? ? ??
    ? ? ? ? .container {
    ? ? ? ? ? ? display: flex;
    ? ? ? ? ? ? flex-wrap: wrap;
    ? ? ? ? ? ? justify-content: center;
    ? ? ? ? ? ? gap: 40px;
    ? ? ? ? ? ? max-width: 1200px;
    ? ? ? ? ? ? margin: 20px auto;
    ? ? ? ? }
    ? ? ? ??
    ? ? ? ? .card {
    ? ? ? ? ? ? background: rgba(255, 255, 255, 0.85);
    ? ? ? ? ? ? border-radius: 20px;
    ? ? ? ? ? ? box-shadow: 0 10px 30px rgba(150, 50, 50, 0.2);
    ? ? ? ? ? ? padding: 25px;
    ? ? ? ? ? ? width: 100%;
    ? ? ? ? ? ? max-width: 500px;
    ? ? ? ? ? ? transition: transform 0.3s ease;
    ? ? ? ? }
    ? ? ? ??
    ? ? ? ? .card:hover {
    ? ? ? ? ? ? transform: translateY(-10px);
    ? ? ? ? }
    ? ? ? ??
    ? ? ? ? .card h2 {
    ? ? ? ? ? ? text-align: center;
    ? ? ? ? ? ? margin-bottom: 20px;
    ? ? ? ? ? ? color: #d83f5d;
    ? ? ? ? ? ? display: flex;
    ? ? ? ? ? ? align-items: center;
    ? ? ? ? ? ? justify-content: center;
    ? ? ? ? ? ? gap: 10px;
    ? ? ? ? }
    ? ? ? ??
    ? ? ? ? .heart-container {
    ? ? ? ? ? ? display: flex;
    ? ? ? ? ? ? justify-content: center;
    ? ? ? ? ? ? align-items: center;
    ? ? ? ? ? ? min-height: 300px;
    ? ? ? ? ? ? margin: 20px 0;
    ? ? ? ? }
    ? ? ? ??
    ? ? ? ? /* 方法1:使用偽元素創建愛心 */
    ? ? ? ? .heart-1 {
    ? ? ? ? ? ? width: 100px;
    ? ? ? ? ? ? height: 100px;
    ? ? ? ? ? ? background-color: #ff5e7d;
    ? ? ? ? ? ? position: relative;
    ? ? ? ? ? ? transform: rotate(-45deg);
    ? ? ? ? ? ? animation: beat-1 1.2s infinite;
    ? ? ? ? }
    ? ? ? ??
    ? ? ? ? .heart-1::before,
    ? ? ? ? .heart-1::after {
    ? ? ? ? ? ? content: "";
    ? ? ? ? ? ? width: 100px;
    ? ? ? ? ? ? height: 100px;
    ? ? ? ? ? ? background-color: #ff5e7d;
    ? ? ? ? ? ? border-radius: 50%;
    ? ? ? ? ? ? position: absolute;
    ? ? ? ? }
    ? ? ? ??
    ? ? ? ? .heart-1::before {
    ? ? ? ? ? ? top: -50px;
    ? ? ? ? ? ? left: 0;
    ? ? ? ? }
    ? ? ? ??
    ? ? ? ? .heart-1::after {
    ? ? ? ? ? ? top: 0;
    ? ? ? ? ? ? left: 50px;
    ? ? ? ? }
    ? ? ? ??
    ? ? ? ? /* 方法2:使用border-radius創建愛心 */
    ? ? ? ? .heart-2 {
    ? ? ? ? ? ? width: 100px;
    ? ? ? ? ? ? height: 100px;
    ? ? ? ? ? ? background-color: #ff3366;
    ? ? ? ? ? ? position: relative;
    ? ? ? ? ? ? animation: beat-2 1.4s infinite;
    ? ? ? ? }
    ? ? ? ??
    ? ? ? ? .heart-2::before,
    ? ? ? ? .heart-2::after {
    ? ? ? ? ? ? content: "";
    ? ? ? ? ? ? position: absolute;
    ? ? ? ? ? ? width: 100px;
    ? ? ? ? ? ? height: 100px;
    ? ? ? ? ? ? background-color: #ff3366;
    ? ? ? ? ? ? border-radius: 50%;
    ? ? ? ? }
    ? ? ? ??
    ? ? ? ? .heart-2::before {
    ? ? ? ? ? ? top: 0;
    ? ? ? ? ? ? left: -50px;
    ? ? ? ? }
    ? ? ? ??
    ? ? ? ? .heart-2::after {
    ? ? ? ? ? ? top: -50px;
    ? ? ? ? ? ? left: 0;
    ? ? ? ? }
    ? ? ? ??
    ? ? ? ? /* 方法3:使用CSS clip-path創建愛心 */
    ? ? ? ? .heart-3 {
    ? ? ? ? ? ? width: 100px;
    ? ? ? ? ? ? height: 90px;
    ? ? ? ? ? ? background-color: #ff1493;
    ? ? ? ? ? ? clip-path: path("M10,30 A20,20,0,0,1,50,30 A20,20,0,0,1,90,30 Q90,60,50,90 Q10,60,10,30 Z");
    ? ? ? ? ? ? animation: beat-3 1.6s infinite;
    ? ? ? ? }
    ? ? ? ??
    ? ? ? ? /* 方法4:使用SVG創建愛心 */
    ? ? ? ? .heart-4 {
    ? ? ? ? ? ? width: 100px;
    ? ? ? ? ? ? height: 100px;
    ? ? ? ? ? ? animation: beat-4 1.8s infinite;
    ? ? ? ? }
    ? ? ? ??
    ? ? ? ? .heart-4 svg {
    ? ? ? ? ? ? width: 100%;
    ? ? ? ? ? ? height: 100%;
    ? ? ? ? }
    ? ? ? ??
    ? ? ? ? /* 方法5:文字愛心 */
    ? ? ? ? .heart-5 {
    ? ? ? ? ? ? font-size: 100px;
    ? ? ? ? ? ? color: #ff5e7d;
    ? ? ? ? ? ? text-shadow: 0 0 20px rgba(255, 0, 85, 0.4);
    ? ? ? ? ? ? animation: beat-5 2s infinite;
    ? ? ? ? }
    ? ? ? ??
    ? ? ? ? /* 動畫效果 */
    ? ? ? ? @keyframes beat-1 {
    ? ? ? ? ? ? 0%, 100% { transform: rotate(-45deg) scale(1); }
    ? ? ? ? ? ? 50% { transform: rotate(-45deg) scale(1.1); }
    ? ? ? ? }
    ? ? ? ??
    ? ? ? ? @keyframes beat-2 {
    ? ? ? ? ? ? 0%, 100% { transform: scale(1); }
    ? ? ? ? ? ? 50% { transform: scale(1.1); }
    ? ? ? ? }
    ? ? ? ??
    ? ? ? ? @keyframes beat-3 {
    ? ? ? ? ? ? 0%, 100% { transform: scale(1); }
    ? ? ? ? ? ? 50% { transform: scale(1.15); }
    ? ? ? ? }
    ? ? ? ??
    ? ? ? ? @keyframes beat-4 {
    ? ? ? ? ? ? 0%, 100% { transform: scale(1); }
    ? ? ? ? ? ? 50% { transform: scale(1.12); }
    ? ? ? ? }
    ? ? ? ??
    ? ? ? ? @keyframes beat-5 {
    ? ? ? ? ? ? 0%, 100% { transform: scale(1); }
    ? ? ? ? ? ? 50% { transform: scale(1.2); }
    ? ? ? ? }
    ? ? ? ??
    ? ? ? ? .code-block {
    ? ? ? ? ? ? background: #2d2d2d;
    ? ? ? ? ? ? color: #f8f8f2;
    ? ? ? ? ? ? border-radius: 10px;
    ? ? ? ? ? ? padding: 15px;
    ? ? ? ? ? ? margin-top: 20px;
    ? ? ? ? ? ? font-family: 'Courier New', monospace;
    ? ? ? ? ? ? font-size: 0.9rem;
    ? ? ? ? ? ? line-height: 1.5;
    ? ? ? ? ? ? overflow-x: auto;
    ? ? ? ? ? ? max-height: 200px;
    ? ? ? ? ? ? overflow-y: auto;
    ? ? ? ? }
    ? ? ? ??
    ? ? ? ? .generator {
    ? ? ? ? ? ? background: rgba(255, 255, 255, 0.85);
    ? ? ? ? ? ? border-radius: 20px;
    ? ? ? ? ? ? box-shadow: 0 10px 30px rgba(150, 50, 50, 0.2);
    ? ? ? ? ? ? padding: 30px;
    ? ? ? ? ? ? width: 100%;
    ? ? ? ? ? ? max-width: 800px;
    ? ? ? ? ? ? margin: 40px auto;
    ? ? ? ? ? ? text-align: center;
    ? ? ? ? }
    ? ? ? ??
    ? ? ? ? .controls {
    ? ? ? ? ? ? display: flex;
    ? ? ? ? ? ? flex-wrap: wrap;
    ? ? ? ? ? ? justify-content: center;
    ? ? ? ? ? ? gap: 20px;
    ? ? ? ? ? ? margin: 30px 0;
    ? ? ? ? }
    ? ? ? ??
    ? ? ? ? .control-group {
    ? ? ? ? ? ? display: flex;
    ? ? ? ? ? ? flex-direction: column;
    ? ? ? ? ? ? align-items: center;
    ? ? ? ? }
    ? ? ? ??
    ? ? ? ? label {
    ? ? ? ? ? ? margin-bottom: 8px;
    ? ? ? ? ? ? font-weight: 500;
    ? ? ? ? ? ? color: #7a1f1f;
    ? ? ? ? }
    ? ? ? ??
    ? ? ? ? input[type="range"] {
    ? ? ? ? ? ? width: 200px;
    ? ? ? ? ? ? accent-color: #ff5e7d;
    ? ? ? ? }
    ? ? ? ??
    ? ? ? ? input[type="color"] {
    ? ? ? ? ? ? width: 60px;
    ? ? ? ? ? ? height: 40px;
    ? ? ? ? ? ? border: none;
    ? ? ? ? ? ? border-radius: 8px;
    ? ? ? ? ? ? cursor: pointer;
    ? ? ? ? }
    ? ? ? ??
    ? ? ? ? .generated-heart {
    ? ? ? ? ? ? margin: 30px auto;
    ? ? ? ? ? ? width: 150px;
    ? ? ? ? ? ? height: 150px;
    ? ? ? ? ? ? background-color: #ff5e7d;
    ? ? ? ? ? ? position: relative;
    ? ? ? ? ? ? transform: rotate(-45deg);
    ? ? ? ? }
    ? ? ? ??
    ? ? ? ? .generated-heart::before,
    ? ? ? ? .generated-heart::after {
    ? ? ? ? ? ? content: "";
    ? ? ? ? ? ? position: absolute;
    ? ? ? ? ? ? width: 150px;
    ? ? ? ? ? ? height: 150px;
    ? ? ? ? ? ? background-color: inherit;
    ? ? ? ? ? ? border-radius: 50%;
    ? ? ? ? }
    ? ? ? ??
    ? ? ? ? .generated-heart::before {
    ? ? ? ? ? ? top: -75px;
    ? ? ? ? ? ? left: 0;
    ? ? ? ? }
    ? ? ? ??
    ? ? ? ? .generated-heart::after {
    ? ? ? ? ? ? top: 0;
    ? ? ? ? ? ? left: 75px;
    ? ? ? ? }
    ? ? ? ??
    ? ? ? ? button {
    ? ? ? ? ? ? background: #ff5e7d;
    ? ? ? ? ? ? color: white;
    ? ? ? ? ? ? border: none;
    ? ? ? ? ? ? padding: 12px 25px;
    ? ? ? ? ? ? border-radius: 50px;
    ? ? ? ? ? ? font-size: 1rem;
    ? ? ? ? ? ? font-weight: 600;
    ? ? ? ? ? ? cursor: pointer;
    ? ? ? ? ? ? transition: all 0.3s ease;
    ? ? ? ? ? ? margin: 10px;
    ? ? ? ? ? ? box-shadow: 0 4px 15px rgba(255, 94, 125, 0.4);
    ? ? ? ? }
    ? ? ? ??
    ? ? ? ? button:hover {
    ? ? ? ? ? ? background: #ff3366;
    ? ? ? ? ? ? transform: translateY(-3px);
    ? ? ? ? ? ? box-shadow: 0 7px 20px rgba(255, 94, 125, 0.6);
    ? ? ? ? }
    ? ? ? ??
    ? ? ? ? footer {
    ? ? ? ? ? ? text-align: center;
    ? ? ? ? ? ? padding: 30px 0;
    ? ? ? ? ? ? width: 100%;
    ? ? ? ? ? ? max-width: 1200px;
    ? ? ? ? ? ? color: #5a2a2a;
    ? ? ? ? ? ? font-size: 1rem;
    ? ? ? ? ? ? margin-top: auto;
    ? ? ? ? }
    ? ? ? ??
    ? ? ? ? @media (max-width: 768px) {
    ? ? ? ? ? ? .container {
    ? ? ? ? ? ? ? ? flex-direction: column;
    ? ? ? ? ? ? ? ? align-items: center;
    ? ? ? ? ? ? }
    ? ? ? ? ? ??
    ? ? ? ? ? ? .card {
    ? ? ? ? ? ? ? ? max-width: 90%;
    ? ? ? ? ? ? }
    ? ? ? ? ? ??
    ? ? ? ? ? ? h1 {
    ? ? ? ? ? ? ? ? font-size: 2.2rem;
    ? ? ? ? ? ? }
    ? ? ? ? ? ??
    ? ? ? ? ? ? .controls {
    ? ? ? ? ? ? ? ? flex-direction: column;
    ? ? ? ? ? ? ? ? align-items: center;
    ? ? ? ? ? ? }
    ? ? ? ? }
    ? ? </style>
    </head>
    <body>
    ? ? <header>
    ? ? ? ? <h1><i class="fas fa-heart"></i> HTML愛心圖實戰</h1>
    ? ? ? ? <p class="subtitle">探索使用純CSS和HTML創建愛心的多種方法。從基礎形狀到高級技巧,學習如何實現各種風格的愛心及其動畫效果。</p>
    ? ? </header>
    ? ??
    ? ? <div class="container">
    ? ? ? ? <div class="card">
    ? ? ? ? ? ? <h2><i class="fas fa-shapes"></i> 偽元素方法</h2>
    ? ? ? ? ? ? <div class="heart-container">
    ? ? ? ? ? ? ? ? <div class="heart-1"></div>
    ? ? ? ? ? ? </div>
    ? ? ? ? ? ? <div class="code-block">
    /* 使用兩個偽元素創建愛心 */
    .heart {
    ? width: 100px;
    ? height: 100px;
    ? background-color: #ff5e7d;
    ? position: relative;
    ? transform: rotate(-45deg);
    }

    .heart::before,
    .heart::after {
    ? content: "";
    ? width: 100px;
    ? height: 100px;
    ? background-color: #ff5e7d;
    ? border-radius: 50%;
    ? position: absolute;
    }

    .heart::before {
    ? top: -50px;
    ? left: 0;
    }

    .heart::after {
    ? top: 0;
    ? left: 50px;
    }</div>
    ? ? ? ? </div>
    ? ? ? ??
    ? ? ? ? <div class="card">
    ? ? ? ? ? ? <h2><i class="fas fa-border-style"></i> Border-radius方法</h2>
    ? ? ? ? ? ? <div class="heart-container">
    ? ? ? ? ? ? ? ? <div class="heart-2"></div>
    ? ? ? ? ? ? </div>
    ? ? ? ? ? ? <div class="code-block">
    /* 使用border-radius創建愛心 */
    .heart {
    ? width: 100px;
    ? height: 100px;
    ? background-color: #ff3366;
    ? position: relative;
    }

    .heart::before,
    .heart::after {
    ? content: "";
    ? position: absolute;
    ? width: 100px;
    ? height: 100px;
    ? background-color: #ff3366;
    ? border-radius: 50%;
    }

    .heart::before {
    ? top: 0;
    ? left: -50px;
    }

    .heart::after {
    ? top: -50px;
    ? left: 0;
    }</div>
    ? ? ? ? </div>
    ? ? ? ??
    ? ? ? ? <div class="card">
    ? ? ? ? ? ? <h2><i class="fas fa-cut"></i> Clip-path方法</h2>
    ? ? ? ? ? ? <div class="heart-container">
    ? ? ? ? ? ? ? ? <div class="heart-3"></div>
    ? ? ? ? ? ? </div>
    ? ? ? ? ? ? <div class="code-block">
    /* 使用CSS clip-path創建愛心 */
    .heart {
    ? width: 100px;
    ? height: 90px;
    ? background-color: #ff1493;
    ? clip-path: path("M10,30 A20,20,0,0,1,50,30 A20,20,0,0,1,90,30 Q90,60,50,90 Q10,60,10,30 Z");
    }</div>
    ? ? ? ? </div>
    ? ? ? ??
    ? ? ? ? <div class="card">
    ? ? ? ? ? ? <h2><i class="fas fa-code"></i> SVG方法</h2>
    ? ? ? ? ? ? <div class="heart-container">
    ? ? ? ? ? ? ? ? <div class="heart-4">
    ? ? ? ? ? ? ? ? ? ? <svg viewBox="0 0 32 29.6">
    ? ? ? ? ? ? ? ? ? ? ? ? <path d="M23.6,0c-3.4,0-6.3,2.7-7.6,5.6C14.7,2.7,11.8,0,8.4,0C3.8,0,0,3.8,0,8.4c0,9.4,9.5,11.9,16,21.2
    ? ? ? ? ? ? ? ? ? ? ? ? c6.1-9.3,16-12.1,16-21.2C32,3.8,28.2,0,23.6,0z" fill="#ff5e7d"/>
    ? ? ? ? ? ? ? ? ? ? </svg>
    ? ? ? ? ? ? ? ? </div>
    ? ? ? ? ? ? </div>
    ? ? ? ? ? ? <div class="code-block">
    <!-- 使用內聯SVG創建愛心 -->
    &lt;svg viewBox="0 0 32 29.6"&gt;
    ? &lt;path d="M23.6,0c-3.4,0-6.3,2.7-7.6,5.6C14.7,2.7,11.8,0,8.4,0C3.8,0,0,3.8,0,8.4c0,9.4,9.5,11.9,16,21.2
    ? c6.1-9.3,16-12.1,16-21.2C32,3.8,28.2,0,23.6,0z" fill="#ff5e7d"/&gt;
    &lt;/svg&gt;</div>
    ? ? ? ? </div>
    ? ? </div>
    ? ??
    ? ? <div class="generator">
    ? ? ? ? <h2><i class="fas fa-magic"></i> 愛心生成器</h2>
    ? ? ? ? <p>自定義您的愛心:調整大小、顏色和動畫速度</p>
    ? ? ? ??
    ? ? ? ? <div class="controls">
    ? ? ? ? ? ? <div class="control-group">
    ? ? ? ? ? ? ? ? <label for="size">尺寸: <span id="size-value">150px</span></label>
    ? ? ? ? ? ? ? ? <input type="range" id="size" min="50" max="300" value="150">
    ? ? ? ? ? ? </div>
    ? ? ? ? ? ??
    ? ? ? ? ? ? <div class="control-group">
    ? ? ? ? ? ? ? ? <label for="color">顏色</label>
    ? ? ? ? ? ? ? ? <input type="color" id="color" value="#ff5e7d">
    ? ? ? ? ? ? </div>
    ? ? ? ? ? ??
    ? ? ? ? ? ? <div class="control-group">
    ? ? ? ? ? ? ? ? <label for="speed">動畫速度: <span id="speed-value">正常</span></label>
    ? ? ? ? ? ? ? ? <input type="range" id="speed" min="0" max="10" value="5">
    ? ? ? ? ? ? </div>
    ? ? ? ? </div>
    ? ? ? ??
    ? ? ? ? <div class="heart-container">
    ? ? ? ? ? ? <div class="generated-heart" id="custom-heart"></div>
    ? ? ? ? </div>
    ? ? ? ??
    ? ? ? ? <button id="animate-btn"><i class="fas fa-play"></i> 播放動畫</button>
    ? ? ? ? <button id="reset-btn"><i class="fas fa-redo"></i> 重置</button>
    ? ? </div>
    ? ??
    ? ? <footer>
    ? ? ? ? <p>? 2023 HTML愛心圖實戰 | 使用純CSS和HTML創建 | 探索前端設計的藝術</p>
    ? ? ? ? <p>?? 讓愛在代碼中傳遞 ??</p>
    ? ? </footer>

    ? ? <script>
    ? ? ? ? // 獲取DOM元素
    ? ? ? ? const sizeSlider = document.getElementById('size');
    ? ? ? ? const colorPicker = document.getElementById('color');
    ? ? ? ? const speedSlider = document.getElementById('speed');
    ? ? ? ? const customHeart = document.getElementById('custom-heart');
    ? ? ? ? const animateBtn = document.getElementById('animate-btn');
    ? ? ? ? const resetBtn = document.getElementById('reset-btn');
    ? ? ? ? const sizeValue = document.getElementById('size-value');
    ? ? ? ? const speedValue = document.getElementById('speed-value');
    ? ? ? ??
    ? ? ? ? // 更新尺寸顯示
    ? ? ? ? sizeSlider.addEventListener('input', function() {
    ? ? ? ? ? ? const size = this.value;
    ? ? ? ? ? ? sizeValue.textContent = `${size}px`;
    ? ? ? ? ? ??
    ? ? ? ? ? ? // 更新愛心尺寸
    ? ? ? ? ? ? customHeart.style.width = `${size}px`;
    ? ? ? ? ? ? customHeart.style.height = `${size}px`;
    ? ? ? ? ? ??
    ? ? ? ? ? ? // 更新偽元素尺寸
    ? ? ? ? ? ? const pseudoSize = `${size}px`;
    ? ? ? ? ? ? customHeart.style.setProperty('--pseudo-size', pseudoSize);
    ? ? ? ? ? ??
    ? ? ? ? ? ? // 更新偽元素位置
    ? ? ? ? ? ? const pseudoOffset = `${size / 2}px`;
    ? ? ? ? ? ? customHeart.style.setProperty('--pseudo-offset', pseudoOffset);
    ? ? ? ? });
    ? ? ? ??
    ? ? ? ? // 更新顏色
    ? ? ? ? colorPicker.addEventListener('input', function() {
    ? ? ? ? ? ? customHeart.style.backgroundColor = this.value;
    ? ? ? ? });
    ? ? ? ??
    ? ? ? ? // 更新速度顯示
    ? ? ? ? speedSlider.addEventListener('input', function() {
    ? ? ? ? ? ? const speed = this.value;
    ? ? ? ? ? ? let speedText;
    ? ? ? ? ? ??
    ? ? ? ? ? ? if (speed < 3) speedText = '慢速';
    ? ? ? ? ? ? else if (speed < 7) speedText = '正常';
    ? ? ? ? ? ? else speedText = '快速';
    ? ? ? ? ? ??
    ? ? ? ? ? ? speedValue.textContent = speedText;
    ? ? ? ? });
    ? ? ? ??
    ? ? ? ? // 動畫按鈕事件
    ? ? ? ? animateBtn.addEventListener('click', function() {
    ? ? ? ? ? ? const speed = speedSlider.value;
    ? ? ? ? ? ? const duration = 2 - (speed * 0.15); // 根據速度計算動畫時長
    ? ? ? ? ? ??
    ? ? ? ? ? ? customHeart.style.animation = `none`;
    ? ? ? ? ? ? setTimeout(() => {
    ? ? ? ? ? ? ? ? customHeart.style.animation = `beat ${duration}s infinite`;
    ? ? ? ? ? ? }, 10);
    ? ? ? ? });
    ? ? ? ??
    ? ? ? ? // 重置按鈕事件
    ? ? ? ? resetBtn.addEventListener('click', function() {
    ? ? ? ? ? ? // 重置滑塊和值
    ? ? ? ? ? ? sizeSlider.value = 150;
    ? ? ? ? ? ? colorPicker.value = '#ff5e7d';
    ? ? ? ? ? ? speedSlider.value = 5;
    ? ? ? ? ? ??
    ? ? ? ? ? ? // 更新顯示
    ? ? ? ? ? ? sizeValue.textContent = '150px';
    ? ? ? ? ? ? speedValue.textContent = '正常';
    ? ? ? ? ? ??
    ? ? ? ? ? ? // 重置愛心樣式
    ? ? ? ? ? ? customHeart.style.width = '150px';
    ? ? ? ? ? ? customHeart.style.height = '150px';
    ? ? ? ? ? ? customHeart.style.backgroundColor = '#ff5e7d';
    ? ? ? ? ? ? customHeart.style.animation = 'none';
    ? ? ? ? ? ??
    ? ? ? ? ? ? // 重置偽元素尺寸
    ? ? ? ? ? ? customHeart.style.setProperty('--pseudo-size', '150px');
    ? ? ? ? ? ? customHeart.style.setProperty('--pseudo-offset', '75px');
    ? ? ? ? });
    ? ? ? ??
    ? ? ? ? // 添加CSS動畫關鍵幀
    ? ? ? ? const style = document.createElement('style');
    ? ? ? ? style.textContent = `
    ? ? ? ? ? ? @keyframes beat {
    ? ? ? ? ? ? ? ? 0%, 100% { transform: rotate(-45deg) scale(1); }
    ? ? ? ? ? ? ? ? 50% { transform: rotate(-45deg) scale(1.15); }
    ? ? ? ? ? ? }
    ? ? ? ? `;
    ? ? ? ? document.head.appendChild(style);
    ? ? </script>
    </body>
    </html>

  • 功能亮點

  • 五種愛心實現方法

    • 偽元素方法(最常用)

    • Border-radius方法

    • CSS clip-path方法

    • SVG方法

    • 文字方法(使用??字符)

  • 動畫效果

    • 每個愛心都有獨特的脈動動畫

    • 平滑的縮放效果模擬心跳

    • 不同的動畫速度創造多樣化效果

  • 愛心生成器

    • 實時調整愛心尺寸(50px-300px)

    • 自定義愛心顏色

    • 控制動畫速度(慢速/正常/快速)

    • 播放/重置功能

  • 響應式設計

    • 在手機、平板和桌面設備上均完美顯示

    • 在小屏幕設備上自動調整布局

  • 代碼展示

    • 每個方法都附帶源代碼展示

    • 語法高亮提高可讀性

    • 代碼塊可滾動查看

本文來自互聯網用戶投稿,該文觀點僅代表作者本人,不代表本站立場。本站僅提供信息存儲空間服務,不擁有所有權,不承擔相關法律責任。
如若轉載,請注明出處:http://www.pswp.cn/pingmian/83031.shtml
繁體地址,請注明出處:http://hk.pswp.cn/pingmian/83031.shtml
英文地址,請注明出處:http://en.pswp.cn/pingmian/83031.shtml

如若內容造成侵權/違法違規/事實不符,請聯系多彩編程網進行投訴反饋email:809451989@qq.com,一經查實,立即刪除!

相關文章

2022年 中國商務年鑒(excel電子表格版)

2022年 中國商務年鑒&#xff08;excel電子表格版&#xff09;.ziphttps://download.csdn.net/download/2401_84585615/89772883 https://download.csdn.net/download/2401_84585615/89772883 《中國商務年鑒2022》是由商務部國際貿易經濟合作研究院主辦的年度統計資料&#xf…

Redis核心數據結構操作指南:字符串、哈希、列表詳解

注&#xff1a;此為蒼穹外賣學習筆記 Redis作為高性能的鍵值數據庫&#xff0c;其核心價值來自于豐富的數據結構支持。本文將深入解析字符串&#xff08;String&#xff09;、哈希&#xff08;Hash&#xff09;、**列表&#xff08;List&#xff09;**三大基礎結構的操作命令&…

如何以 9 種方式將照片從 iPhone 傳輸到筆記本電腦

您的 iPhone 可能充滿了以照片和視頻形式捕捉的珍貴回憶。無論您是想備份它們、在更大的屏幕上編輯它們&#xff0c;還是只是釋放設備上的空間&#xff0c;您都需要將照片從 iPhone 傳輸到筆記本電腦。幸運的是&#xff0c;有 9 種方便的方法可供使用&#xff0c;同時滿足 Wind…

如何使用Python從MySQL數據庫導出表結構到Word文檔

在開發和維護數據庫的過程中&#xff0c;能夠快速且準確地獲取表結構信息是至關重要的。本文將向您展示一種簡單而有效的方法&#xff0c;利用Python腳本從MySQL數據庫中提取指定表的結構信息&#xff0c;并將其導出為格式化的Word文檔。此方法不僅提高了工作效率&#xff0c;還…

寫作-- 復合句練習

文章目錄 練習 11. 家庭的支持和老師的指導對學生的學術成功有積極影響。2. 缺乏準備和未能適應通常會導致在挑戰性情境中的糟糕表現。3. 吃垃圾食品和忽視鍛煉可能導致嚴重的健康問題,因此人們應注重保持均衡的生活方式。4. 昨天的大雨導致街道洪水泛濫,因此居民們遷往高地以…

QT使用說明

QT環境準備 推薦Ubuntu平臺上使用&#xff0c;配置簡單&#xff0c;坑少。 Ubuntu 20.04 安裝 sudo apt-get install qt5-default -y sudo apt-get install qtcreator -y sudo apt-get install -y libclang-common-8-dev啟動 qtcreatorHelloWorld 打開 Qt Creator。選擇 …

React 第四十九節 Router中useNavigation的具體使用詳解及注意事項

前言 useNavigation 是 React Router 中一個強大的鉤子&#xff0c;用于獲取當前頁面導航的狀態信息。 它可以幫助開發者根據導航狀態優化用戶體驗&#xff0c;如顯示加載指示器、防止重復提交等。 一、useNavigation核心用途 檢測導航狀態&#xff1a;判斷當前是否正在進行…

列表單獨展開收起同時關閉其余子項的問題優化

如圖所示&#xff0c;當在列表中&#xff0c;需要分別單獨點開子選項時&#xff0c;直接這樣用一個index參數判斷即可&#xff0c;非常簡單方便&#xff0c;只需要滿足點開當前index,然后想同index用null值自動關閉即可

WPF【11_5】WPF實戰-重構與美化(MVVM 實戰)

11-10 【重構】創建視圖模型&#xff0c;顯示客戶列表 正式進入 MVVM 架構的代碼實戰。在之前的課程中&#xff0c; Model 和 View 這部分的代碼重構實際上已經完成了。 Model 就是在 Models 文件夾中看到的兩個文件&#xff0c; Customer 和 Appointment。 而 View 則是所有與…

LangChain-結合魔塔社區modelscope的embeddings實現搜索

首先要安裝modelscope pip install modelscope 安裝完成后測試 from langchain_community.embeddings import ModelScopeEmbeddingsembeddings ModelScopeEmbeddings(model_id"iic/nlp_gte_sentence-embedding_chinese-base")text "這是一個測試句子"…

可定制化貨代管理系統,適應不同業務模式需求!

在全球化貿易的浪潮下&#xff0c;貨運代理行業扮演著至關重要的角色。然而&#xff0c;隨著市場競爭的日益激烈&#xff0c;貨代企業面臨著越來越多的挑戰&#xff1a;客戶需求多樣化、業務流程復雜化、運營成本上升、利潤空間壓縮……這些挑戰迫使貨代企業不斷尋求創新和突破…

Lyra學習筆記2 GFA_AddComponents與ULyraPlayerSpawningManagerComponent

目錄 前言GameFeatureAction_AddComponentsULyraPlayerSpawningManagerComponent緩存所有PlayerStart位置選擇位置 前言 1.以control模式為例 2.比較散&#xff0c;想單獨拿出一篇梳理下Experience的流程 GameFeatureAction_AddComponents 這部分建議看 《InsideUE5》GameFeatu…

進程生命周期

進程生命周期 Linux是多任務操作系統&#xff0c;系統中的每個進程能夠分時復用CPU時間片&#xff0c;通過有效的進程調度策略實現多任務并行執行。進程在被CPU調度運行&#xff0c;等待CPU資源分配以及等待外部事件時會處于不同的狀態。進程狀態如下&#xff1a; 創建狀態&a…

文字轉圖片的字符畫生成工具

軟件介紹 今天要介紹的這款軟件可以將文字轉換成圖片的排列形式&#xff0c;非常適合需要將文字圖形化的場景&#xff0c;建議有需要的朋友收藏。 軟件名稱與用途 這款軟件名為《字符畫大師》&#xff0c;是一款在網吧等場所非常流行的聊天輔助工具&#xff0c;其主要功能就…

歷年南京大學計算機保研上機真題

2025南京大學計算機保研上機真題 2024南京大學計算機保研上機真題 2023南京大學計算機保研上機真題 在線測評鏈接&#xff1a;https://pgcode.cn/school Count Number of Binary Strings 題目描述 Given a positive integer n n n ( 3 ≤ n ≤ 90 3 \leq n \leq 90 3≤n≤…

王樹森推薦系統公開課 排序06:粗排模型

shared bottom 表示神經網絡被所有特征共享。精排模型主要開銷在神經網絡&#xff0c;神經網絡很大且很復雜。 每做一次推薦&#xff0c;用戶塔只做一次推理。物品塔存放入向量數據庫。 后期融合模型常用于召回&#xff0c;前期融合模型常用于精排。 物品塔短時間內比較穩…

VSCode的下載與安裝(2025親測有效)

目錄 0 前言1 下載2 安裝3 后記 0 前言 丫的&#xff0c;誰懂啊&#xff0c;嘗試了各種辦法不行的話&#xff0c;我就不得不拿出我的最后絕招了&#xff0c;卸載&#xff0c;重新安裝&#xff0c;我經常要重新安裝&#xff0c;所以自己寫了一個博客&#xff0c;給自己&#xf…

端午節互動網站

端午節互動網站 項目介紹 這是一個基于 Vue 3 Vite 開發的端午節主題互動網站&#xff0c;旨在通過有趣的交互方式展示中國傳統端午節文化。網站包含三個主要功能模塊&#xff1a;端午節介紹、互動包粽子游戲和龍舟競賽游戲。 預覽網站&#xff1a;https://duanwujiekuaile…

Python+requests+pytest接口自動化測試框架的搭建(全)

&#x1f345; 點擊文末小卡片&#xff0c;免費獲取軟件測試全套資料&#xff0c;資料在手&#xff0c;漲薪更快 框架的設計思路 首先要明確進行接口自動化需要的步驟&#xff0c;如下圖所示&#xff1a; 然后逐步拆解需要完成的工作&#xff1a; 1&#xff09;了解分析需求&…

OpenCV視覺圖片調整:從基礎到實戰的技術指南

引言:數字圖像處理的現代意義與OpenCV深度應用 在人工智能與計算機視覺蓬勃發展的今天,圖像處理技術已成為多個高科技領域的核心支撐。根據市場研究機構Grand View Research的數據,全球計算機視覺市場規模預計將從2022年的125億美元增長到2030年的253億美元,年復合增長率達…