Menu
Coddy logo textTech

テーマ付きブログページ

CoddyのHTMLジャーニー「JavaScriptの実践」セクションの一部。レッスン 27/27。

challenge icon

チャレンジ

簡単

このチャレンジでは、photographyブログページとしてLens & Lightというページを作成します。photographyのヒントに関するブログ記事、dark/light Themeの切り替えボタン、送信時にToastメッセージを表示するシンプルなNewsletter signup formが含まれています。

このphotographyブログページのHTMLとCSSはすでに用意されています。あなたの課題は、JavaScriptの機能を追加することです。

  1. Theme switch:toggle buttonにイベントリスナーを追加します。buttonがクリックされたとき、dark-modeクラスを<body>に対して切り替え、Themeが変わるようにします。
  2. Toast message:formが送信されたとき、Toast要素から"hidden"クラスを削除し、Toast要素に"show"クラスを追加して、Toastを表示します。

自分で試してみよう

<!DOCTYPE html>
<html>
<head>
  <title>Photographer's Blog</title>
  <link rel="stylesheet" href="style.css">
</head>
<body>
  <header>
    <h1>Lens & Light</h1>
    <button id="themeToggle">Toggle Theme</button>
  </header>

  <main>
    <article class="post">
      <h2>Capturing Golden Hour</h2>
      <p>
        The hour before sunset and after sunrise brings warm, soft light that adds 
        depth and atmosphere to portraits and landscapes. Every photographer should 
        experiment with golden hour lighting.
      </p>
    </article>

    <article class="post">
      <h2>5 Tips for Street Photography</h2>
      <p>
        Look for interesting shadows, capture candid emotions, blend into the crowd, 
        use a prime lens, and always be ready to click. Street photography is about 
        telling raw and authentic stories.
      </p>
    </article>

    <section class="newsletter">
      <h3>Subscribe to Photo Notes</h3>
      <form id="newsletterForm">
        <input type="email" id="email" placeholder="Enter your email">
        <button type="submit">Sign Up</button>
      </form>
    </section>
  </main>

  <div id="toast" class="toast hidden">Subscribed successfully! 📸</div>

  <script src="script.js"></script>
</body>
</html>

JavaScriptの実践のすべてのレッスン

自分で練習してみよう: Webプレイグラウンド