head> meta charset="UTF-8" /> meta http-equiv="X-UA-Compatible" content="IE=edge" /> meta name="viewport" cont..."/>

CSS-上下滑动翻页效果

12,166次阅读
没有评论

共计 3545 个字符,预计需要花费 9 分钟才能阅读完成。

效果展示
CSS- 上下滑动翻页效果
代码

DOCTYPE html>
html lang="en">
  head>
    meta charset="UTF-8" />
    meta http-equiv="X-UA-Compatible" content="IE=edge" />
    meta name="viewport" content="width=device-width, initial-scale=1.0" />
    
    title>Documenttitle>
  head>
  body>
    div class="hero">
      h1> 人物介绍 h1>
      div class="review-box">
        div id="slide">
          div class="card">
            div class="profile">
              img src="/image/pic1.jpg" />
              div>
                h3>Phoenixh3>
                p>Web Designerp>
              div>
            div>
            p>
              The designer sat at their desk, surrounded by sketches and color
              swatches. They carefully crafted each line and curve, choosing
              just the right hue to bring their vision to life. With a steady
              hand and a sharp eye, they transformed blank pages into beautiful
              works of art.
            p>
          div>
          div class="card">
            div class="profile">
              img src="image/pic2.jpg" />
              div>
                h3>Steve McCurryh3>
                p>UI/UX Designerp>
              div>
            div>
            h3>
              The designer sat at their desk, surrounded by sketches and color
              swatches. They carefully crafted each line and curve, choosing
              just the right hue to bring their vision to life. With a steady
              hand and a sharp eye, they transformed blank pages into beautiful
              works of art.
            h3>
          div>
          div class="card">
            div class="profile">
              img src="image/pic3.jpg" />
              div>
                h3>Merlin Nauvenh3>
                p>Web Designerp>
              div>
            div>
            p>
              The designer sat at their desk, surrounded by sketches and color
              swatches. They carefully crafted each line and curve, choosing
              just the right hue to bring their vision to life. With a steady
              hand and a sharp eye, they transformed blank pages into beautiful
              works of art.
            p>
          div>
          div class="card">
            div class="profile">
              img src="image/pic4.jpg" />
              div>
                h3>John Williamsh3>
                p>Web Designerp>
              div>
            div>
            p>
              The designer sat at their desk, surrounded by sketches and color
              swatches. They carefully crafted each line and curve, choosing
              just the right hue to bring their vision to life. With a steady
              hand and a sharp eye, they transformed blank pages into beautiful
              works of art.
            p>
          div>
        div>
        div class="sidebar">
          
          div id="upArrow">div>
          div id="downArrow">div>
        div>
          
          
        div>
      div>
    div>
    script>
      var slide = document.getElementById('slide')
      var upArrow = document.getElementById('upArrow')
      var downArrow = document.getElementById('downArrow')

      let x = 0

      upArrow.onclick = function () {
        if (x  0) {
          x = x + 300
          slide.style.top = x + 'px'
        }
      }
      downArrow.onclick = function () {
        if (x > -900) {
          x = x - 300
          slide.style.top = x + 'px'
        }
      }
    script>
  body>
html>
style>
  * {
    padding: 0;
    margin: 0;
    font-family: sans-serif;
  }

  .hero {
    width: 100%;
    height: 100vh;
    background: #f6fbff;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
  }

  h1 {
    font-size: 30px;
    position: relative;
    margin-bottom: 60px;
  }

  h1::after {
    content: '';
    width: 150px;
    height: 3px;
    background: linear-gradient(to right, #0780ed, #9f4db5);
    position: absolute;
    bottom: -20px;
    left: 50%;
    transform: translateX(-50%);
  }

  .review-box {
    width: 90%;
    max-width: 700px;
    height: 300px;
    border-radius: 10px;
    box-shadow: -10px 10px 40px rgba(0, 0, 0, 0.25);
    position: relative;
    overflow: hidden;
  }
  #upArrow {
    width: 30px;
    height: 30px;
    border-radius: 50%;
    background-color: #fff;
    text-align: center;
    line-height: 30px;
    cursor: pointer;
  }
  #downArrow {
    width: 30px;
    height: 30px;
    border-radius: 50%;
    background-color: #fff;
    text-align: center;
    line-height: 30px;
    cursor: pointer;
  }
  .card {
    height: 300px;
    padding: 40px;
    color: #111;
    line-height: 22px;
    box-sizing: border-box;
    background: #fff;
    position: relative;
  }

  .profile {
    display: flex;
    align-items: center;
    margin-bottom: 40px;
  }

  .profile img {
    width: 70px;
    border-radius: 50%;
    margin-right: 20px;
  }

  .profile h3 {
    font-size: 26px;
    color: #0780ed;
    margin-bottom: 8px;
  }

  #slide {
    width: 100%;
    padding-right: 60px;
    box-sizing: border-box;
    position: absolute;
    top: 0;
    left: 0;
    transition: 0.5s;
  }

  .sidebar {
    width: 60px;
    height: 100%;
    padding: 15px 0;
    box-sizing: border-box;
    background: #0780ed;
    position: absolute;
    right: 0;
    top: 0;
    display: flex;
    flex-direction: column;
    justify-content: space-between;
    align-items: center;
  }

  .sidebar img {
    width: 25px;
    padding: 5px;
    background: #fff;
    border-radius: 50%;
    cursor: pointer;
  }
style>

Tips:觉得有用的话点个关注呦,会分享更多“有用”的前端 tips

原文地址: CSS- 上下滑动翻页效果

    正文完
     0
    Yojack
    版权声明:本篇文章由 Yojack 于2024-10-14发表,共计3545字。
    转载说明:
    1 本网站名称:优杰开发笔记
    2 本站永久网址:https://yojack.cn
    3 本网站的文章部分内容可能来源于网络,仅供大家学习与参考,如有侵权,请联系站长进行删除处理。
    4 本站一切资源不代表本站立场,并不代表本站赞同其观点和对其真实性负责。
    5 本站所有内容均可转载及分享, 但请注明出处
    6 我们始终尊重原创作者的版权,所有文章在发布时,均尽可能注明出处与作者。
    7 站长邮箱:laylwenl@gmail.com
    评论(没有评论)