探索大自然edit icon

作者:
藤原
Fork(复制)
下载
嵌入
设置
BUG反馈
index.html
style.css
index.js
现在支持上传本地图片了!
            
            <!DOCTYPE html>
<html lang="zh-CN">
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>探索大自然 | Explore the Great Outdoors</title>
  <style>
    @import url("https://fonts.googleapis.com/css2?family=Forum");
    :root {
      --color-accent: #EFE7D2;
      --color-accent-transparent: #EFE7D226;
      --color-dark: #0A0B0A;
      --color-bright: #d1d5db;
      --radius: 1.5rem;
      --color-bg: var(--color-dark);
      color: var(--color-bright);
      background: var(--color-bg);
      font-family: Forum, system-ui;
    }

    *, :after, :before {
      box-sizing: border-box;
    }

    body {
      margin: 0;
    }

    img {
      max-width: 100%;
    }

    h1, h2, h3 {
      margin: 0;
      letter-spacing: 1;
      font-weight: 100;
    }

    .bento {
      display: grid;
      padding: 1rem;
      gap: 1rem;
      grid-template-columns: 1fr;
    }
    @media (width >= 62em) {
      .bento {
        grid-template-columns: 1fr 1fr 1fr 1fr;
      }
    }

    .teaser {
      font-weight: 100;
      font-size: 1rem;
      line-height: 1.8;
      margin: auto;
      display: grid;
      position: relative;
      margin: auto;
      overflow: clip;
      align-items: end;
      aspect-ratio: 5/4;
      width: 100%;
      text-align: right;
      cursor: pointer;
      transition: transform 0.3s ease;
    }
    .teaser:hover {
      transform: scale(1.02);
    }
    .teaser__h1 {
      position: absolute;
      max-width: 44rem;
      text-align: left;
      line-height: 1.2;
      padding: 4rem;
      font-size: 4rem;
      color: #efe7d2;
      text-transform: uppercase;
    }
    .teaser--ouline {
      text-align: center;
      border-radius: var(--radius);
      border: 1px solid var(--color-accent-transparent);
      align-items: center;
      justify-content: center;
      padding: 1rem;
      aspect-ratio: 3/2;
    }
    .teaser--hero {
      aspect-ratio: 62/50;
    }
    @media (width >= 62em) {
      .teaser--hero {
        grid-row: span 3;
        grid-column: span 3;
      }
    }
    .teaser__cover {
      inset: 0;
      position: absolute;
      display: block;
      width: 100%;
      height: 100%;
      border-radius: var(--radius);
      object-fit: cover;
      transition: opacity 0.5s ease;
    }
    .teaser__body {
      grid-column: 1;
      grid-row: 1;
      max-width: 35rem;
      margin-left: auto;
    }
    .teaser__title {
      padding-left: 1.5rem;
      padding-block: 1.25rem 0.25rem;
      position: relative;
      border-radius: var(--radius) 0 0 0;
      font-weight: 200;
      display: inline-block;
      background: var(--color-bg);
      line-height: 1.5;
    }
    .teaser__title:before, .teaser__title:after {
      content: "";
      position: absolute;
      display: block;
      width: calc(var(--radius) * 2);
      background: red;
      aspect-ratio: 1;
      border-radius: var(--radius) 0;
      bottom: 0;
      right: 100%;
      box-shadow: var(--radius) var(--radius) 0 var(--color-bg);
      background: transparent;
    }
    .teaser__title:after {
      right: 0;
      bottom: 100%;
    }
    .teaser__text {
      z-index: 1;
      margin: 0;
      position: relative;
      opacity: 0.7;
    }

    .container {
      padding: 0 2rem;
      margin-block: 4rem;
      margin-inline: auto;
      max-width: 52.5rem;
      width: 100%;
    }

    .action {
      display: inline-flex;
      gap: 0.75rem;
      background: var(--color-dark);
      color: var(--color-bright);
      z-index: 1;
      position: relative;
      align-items: center;
      justify-content: center;
      text-decoration: none;
      text-transform: uppercase;
      letter-spacing: 0.1rem;
    }
    .action__text {
      display: var(--action-text);
    }
    .action--fab {
      --action-text: none;
      width: calc(var(--radius)* 2);
      border-radius: 50%;
    }
    .action__icon {
      border: 1px solid currentcolor;
      border-radius: 50%;
      padding: 0.5rem;
      width: 2rem;
      height: 2rem;
    }
    
    /* 添加交换动画 */
    @keyframes fadeSwap {
      0% { opacity: 1; }
      50% { opacity: 0.5; }
      100% { opacity: 1; }
    }
    .swapping {
      animation: fadeSwap 0.5s ease;
    }
  </style>
</head>
<body>
  <div class="bento">
    <!-- 主横幅 -->
    <div class="teaser teaser--hero" id="main-teaser" data-image="https://picsum.photos/id/177/1440/1440" data-title="探索大自然">
      <img class="teaser__cover" id="main-image" src="https://picsum.photos/id/177/1440/1440" alt="自然景观">
      <h1 class="teaser__h1" id="main-title">探索大自然</h1>
      <div class="teaser__body">
        <div class="teaser__title" id="social-buttons">
          <a class="action action--fab" href="#">
            <span class="action__text">Facebook</span>
            <svg class="action__icon" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 320 512" width="320" height="512" fill="currentColor">
              <path d="M80 299.3V512H196V299.3h86.5l18-97.8H196V166.9c0-51.7 20.3-71.5 72.7-71.5c16.3 0 29.4 .4 37 1.2V7.9C291.4 4 256.4 0 236.2 0C129.3 0 80 50.5 80 159.4v42.1H14v97.8H80z" />
            </svg>
          </a>
          <a class="action action--fab" href="#">
            <span class="action__text">Instagram</span>
            <svg class="action__icon" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 448 512" width="448" height="512" fill="currentColor">
              <path d="M224.1 141c-63.6 0-114.9 51.3-114.9 114.9s51.3 114.9 114.9 114.9S339 319.5 339 255.9 287.7 141 224.1 141zm0 189.6c-41.1 0-74.7-33.5-74.7-74.7s33.5-74.7 74.7-74.7 74.7 33.5 74.7 74.7-33.6 74.7-74.7 74.7zm146.4-194.3c0 14.9-12 26.8-26.8 26.8-14.9 0-26.8-12-26.8-26.8s12-26.8 26.8-26.8 26.8 12 26.8 26.8zm76.1 27.2c-1.7-35.9-9.9-67.7-36.2-93.9-26.2-26.2-58-34.4-93.9-36.2-37-2.1-147.9-2.1-184.9 0-35.8 1.7-67.6 9.9-93.9 36.1s-34.4 58-36.2 93.9c-2.1 37-2.1 147.9 0 184.9 1.7 35.9 9.9 67.7 36.2 93.9s58 34.4 93.9 36.2c37 2.1 147.9 2.1 184.9 0 35.9-1.7 67.7-9.9 93.9-36.2 26.2-26.2 34.4-58 36.2-93.9 2.1-37 2.1-147.8 0-184.8zM398.8 388c-7.8 19.6-22.9 34.7-42.6 42.6-29.5 11.7-99.5 9-132.1 9s-102.7 2.6-132.1-9c-19.6-7.8-34.7-22.9-42.6-42.6-11.7-29.5-9-99.5-9-132.1s-2.6-102.7 9-132.1c7.8-19.6 22.9-34.7 42.6-42.6 29.5-11.7 99.5-9 132.1-9s102.7-2.6 132.1 9c19.6 7.8 34.7 22.9 42.6 42.6 11.7 29.5 9 99.5 9 132.1s2.7 102.7-9 132.1z" />
            </svg>
          </a>
          <a class="action action--fab" href="#" id="reset-button">
            <span class="action__text">重置</span>
            <svg class="action__icon" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 512 512" width="512" height="512" fill="currentColor">
              <path d="M105.1 202.6c7.7-21.8 20.2-42.3 37.8-59.8c62.5-62.5 163.8-62.5 226.3 0L386.3 160H336c-17.7 0-32 14.3-32 32s14.3 32 32 32H463.5c0 0 0 0 0 0h.4c17.7 0 32-14.3 32-32V64c0-17.7-14.3-32-32-32s-32 14.3-32 32v51.2L414.4 97.6c-87.5-87.5-229.3-87.5-316.8 0C73.2 122 55.6 150.7 44.8 181.4c-5.9 16.7 2.9 34.9 19.5 40.8s34.9-2.9 40.8-19.5zM39 289.3c-5 1.5-9.8 4.2-13.7 8.2c-4 4-6.7 8.8-8.1 14c-.3 1.2-.6 2.5-.8 3.8c-.3 1.7-.4 3.4-.4 5.1V448c0 17.7 14.3 32 32 32s32-14.3 32-32V396.9l17.6 17.5 0 0c87.5 87.4 229.3 87.4 316.7 0c24.4-24.4 42.1-53.1 52.9-83.7c5.9-16.7-2.9-34.9-19.5-40.8s-34.9 2.9-40.8 19.5c-7.7 21.8-20.2 42.3-37.8 59.8c-62.5 62.5-163.8 62.5-226.3 0l-.1-.1L125.6 352H176c17.7 0 32-14.3 32-32s-14.3-32-32-32H48.4c-1.6 0-3.2 .1-4.8 .3s-3.1 .5-4.6 1z"/>
            </svg>
          </a>
        </div>
      </div>
    </div>
    
    <!-- 瀑布 -->
    <div class="teaser" data-image="https://picsum.photos/id/872/600/450" data-title="瀑布">
      <img class="teaser__cover" src="https://picsum.photos/id/872/600/450" alt="瀑布景观">
      <div class="teaser__body">
        <div class="teaser__title">
          <a class="action" href="#">
            <span class="action__text">瀑布</span>
            <svg class="action__icon" xmlns="http://www.w3.org/2000/svg" viewBox="0 -960 960 960" width="24" height="24" fill="currentColor">
              <path d="M696-462H196v-35h500L455-738l25-26 284 284-283 284-25-26 240-240Z" />
            </svg>
          </a>
        </div>
      </div>
    </div>
    
    <!-- 山顶 -->
    <div class="teaser" data-image="https://picsum.photos/id/575/600/450" data-title="山顶">
      <img class="teaser__cover" src="https://picsum.photos/id/575/600/450" alt="山顶景观">
      <div class="teaser__body">
        <div class="teaser__title">
          <a class="action" href="#">
            <span class="action__text">山顶</span>
            <svg class="action__icon" xmlns="http://www.w3.org/2000/svg" viewBox="0 -960 960 960" width="24" height="24" fill="currentColor">
              <path d="M696-462H196v-35h500L455-738l25-26 284 284-283 284-25-26 240-240Z" />
            </svg>
          </a>
        </div>
      </div>
    </div>
    
    <!-- 古老森林 -->
    <div class="teaser" data-image="https://picsum.photos/id/704/600/450" data-title="古老森林">
      <img class="teaser__cover" src="https://picsum.photos/id/704/600/450" alt="古老森林">
      <div class="teaser__body">
        <div class="teaser__title">
          <a class="action" href="#">
            <span class="action__text">古老森林</span>
            <svg class="action__icon" xmlns="http://www.w3.org/2000/svg" viewBox="0 -960 960 960" width="24" height="24" fill="currentColor">
              <path d="M696-462H196v-35h500L455-738l25-26 284 284-283 284-25-26 240-240Z" />
            </svg>
          </a>
        </div>
      </div>
    </div>
    
    <!-- 信息卡片1 -->
    <div class="teaser teaser--ouline">
      <div class="teaser__body">
        <h2 class="teaser__header">3个露营地</h2>
        <p class="teaser__text">在维护良好的露营地体验大自然中的过夜。</p>
      </div>
    </div>
    
    <!-- 信息卡片2 -->
    <div class="teaser teaser--ouline">
      <div class="teaser__body">
        <h2 class="teaser__header">冬季冒险</h2>
        <p class="teaser__text">雪鞋行走和越野滑雪。</p>
      </div>
    </div>
    
    <!-- 信息卡片3 -->
    <div class="teaser teaser--ouline">
      <div class="teaser__body">
        <h2 class="teaser__header">观星机会</h2>
        <p class="teaser__text">晴朗的天空带来壮观的夜景。</p>
      </div>
    </div>
    
    <!-- 信息卡片4 -->
    <div class="teaser teaser--ouline">
      <div class="teaser__body">
        <h2 class="teaser__header">摄影点</h2>
        <p class="teaser__text">拍摄自然风光的标志性地点。</p>
      </div>
    </div>
  </div>

<script>
  document.addEventListener('DOMContentLoaded', function() {
    // 获取主卡片元素
    const mainTeaser = document.getElementById('main-teaser');
    const mainImage = document.getElementById('main-image');
    const mainTitle = document.getElementById('main-title');
    const socialButtons = document.getElementById('social-buttons');
    const resetButton = document.getElementById('reset-button');
    
    // 获取所有小卡片(不包括主卡片和信息卡片)
    const smallTeasers = document.querySelectorAll('.teaser:not(.teaser--hero):not(.teaser--ouline)');
    
    // 为每个小卡片添加点击事件
    smallTeasers.forEach(teaser => {
      teaser.addEventListener('click', function() {
        // 添加交换动画类
        mainTeaser.classList.add('swapping');
        this.classList.add('swapping');
        
        // 动画结束后执行交换
        setTimeout(() => {
          // 交换数据属性
          const mainImageUrl = mainTeaser.getAttribute('data-image');
          const mainImageAlt = mainImage.alt;
          const mainTitleText = mainTitle.textContent;
          
          const teaserImageUrl = this.getAttribute('data-image');
          const teaserImageAlt = this.querySelector('img').alt;
          const teaserTitleText = this.getAttribute('data-title');
          
          // 交换主卡片和小卡片的内容
          mainTeaser.setAttribute('data-image', teaserImageUrl);
          mainImage.src = teaserImageUrl;
          mainImage.alt = teaserImageAlt;
          mainTitle.textContent = teaserTitleText;
          
          this.setAttribute('data-image', mainImageUrl);
          this.querySelector('img').src = mainImageUrl;
          this.querySelector('img').alt = mainImageAlt;
          this.setAttribute('data-title', mainTitleText);
          this.querySelector('.action__text').textContent = mainTitleText;
          
          // 移除动画类
          mainTeaser.classList.remove('swapping');
          this.classList.remove('swapping');
        }, 250); // 与动画时间匹配
      });
    });
    
    // 添加重置功能到刷新按钮
    resetButton.addEventListener('click', function(e) {
      e.preventDefault();
      e.stopPropagation();
      
      // 重置主卡片
      mainTeaser.setAttribute('data-image', 'https://picsum.photos/id/177/1440/1440');
      mainImage.src = 'https://picsum.photos/id/177/1440/1440';
      mainImage.alt = '自然景观';
      mainTitle.textContent = '探索大自然';
      socialButtons.style.display = 'block';
      
      // 重置所有小卡片
      const teasers = [
        { element: smallTeasers[0], image: 'https://picsum.photos/id/872/600/450', title: '瀑布' },
        { element: smallTeasers[1], image: 'https://picsum.photos/id/575/600/450', title: '山顶' },
        { element: smallTeasers[2], image: 'https://picsum.photos/id/704/600/450', title: '古老森林' }
      ];
      
      teasers.forEach(teaser => {
        teaser.element.setAttribute('data-image', teaser.image);
        teaser.element.querySelector('img').src = teaser.image;
        teaser.element.querySelector('img').alt = teaser.title + '景观';
        teaser.element.setAttribute('data-title', teaser.title);
        teaser.element.querySelector('.action__text').textContent = teaser.title;
      });
    });

    // ====== 新增的社交媒体跳转代码 ======
    // 获取Facebook和Instagram按钮
    const facebookBtn = document.querySelector('.action--fab:nth-of-type(1)');
    const instagramBtn = document.querySelector('.action--fab:nth-of-type(2)');

    // 添加Facebook跳转功能
    facebookBtn.addEventListener('click', function(e) {
      e.preventDefault();
      e.stopPropagation();
      window.open('https://www.facebook.com', '_blank');
    });

    // 添加Instagram跳转功能
    instagramBtn.addEventListener('click', function(e) {
      e.preventDefault();
      e.stopPropagation();
      window.open('https://www.instagram.com', '_blank');
    });
    // ====== 社交媒体跳转代码结束 ======
  });
</script>
</body>
</html>
        
预览
控制台