manyo 發表於 2024-8-17 02:05:07

展不展開

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Collapsible News Articles with YouTube</title>
    <style>
      .collapsible {
            background-color: #f1f1f1;
            color: #444;
            cursor: pointer;
            padding: 10px;
            width: 100%;
            border: none;
            text-align: left;
            font-size: 16px;
            border-radius: 5px;
            outline: none;
            transition: background-color 0.3s;
      }

      .collapsible:hover {
            background-color: #ddd;
      }

      .content {
            padding: 0 18px;
            display: none;
            overflow: hidden;
            background-color: white;
            border-radius: 0 0 5px 5px;
      }

      .arrow {
            float: right;
            margin-left: 10px;
            transition: transform 0.3s;
      }

      .arrow.open {
            transform: rotate(180deg);
      }

      .youtube-container {
            display: none;
      }

      .youtube-container iframe {
            width: 100%;
            height: 315px;
      }
    </style>
</head>
<body>

<h2>News Articles</h2>

<button class="collapsible">Article 1 <span class="arrow">▼</span></button>
<div class="content">
    <p>This is the content of the first article.</p>
    <div class="youtube-container">
      <iframe src="" data-src="https://www.youtube.com/embed/VIDEO_ID_1" frameborder="0" allowfullscreen></iframe>
    </div>
</div>

<button class="collapsible">Article 2 <span class="arrow">▼</span></button>
<div class="content">
    <p>This is the content of the second article.</p>
    <div class="youtube-container">
      <iframe src="" data-src="https://www.youtube.com/embed/VIDEO_ID_2" frameborder="0" allowfullscreen></iframe>
    </div>
</div>

<script>
    document.querySelectorAll('.collapsible').forEach(button => {
      button.addEventListener('click', function() {
            const content = this.nextElementSibling;
            const arrow = this.querySelector('.arrow');
            const youtubeContainer = content.querySelector('.youtube-container');

            if (content.style.display === 'block') {
                content.style.display = 'none';
                arrow.classList.remove('open');
                youtubeContainer.style.display = 'none';
                content.querySelector('iframe').src = '';
            } else {
                content.style.display = 'block';
                arrow.classList.add('open');
                youtubeContainer.style.display = 'block';
                const iframe = youtubeContainer.querySelector('iframe');
                iframe.src = iframe.getAttribute('data-src');
            }
      });
    });
</script>

</body>
</html>
頁: [1]
查看完整版本: 展不展開

一粒米 | 中興米 | 論壇美工 | 設計 抗ddos | 天堂私服 | ddos | ddos | 防ddos | 防禦ddos | 防ddos主機 | 天堂美工 | 設計 防ddos主機 | 抗ddos主機 | 抗ddos | 抗ddos主機 | 抗攻擊論壇 | 天堂自動贊助 | 免費論壇 | 天堂私服 | 天堂123 | 台南清潔 | 天堂 | 天堂私服 | 免費論壇申請 | 抗ddos | 虛擬主機 | 實體主機 | vps | 網域註冊 | 抗攻擊遊戲主機 | ddos |