Use css to achieve visual effects poor

Reference article: https://blog.csdn.net/TriDiamond6/article/details/105222289?depth_1-utm_source=distribute.pc_category.none-task-blog-hot-1&request_id=&utm_source=distribute.pc_category.none-task-blog -hot-1

 Preview: http://tridiamond.me/frontend-tutorials/parallaxImages/

html layout:

<body>
   <div class="wrapper">
     <div class="parallax-img1">
       <div class="caption">
         <span>
           <img
             src="../images/TriDiamond_logo_circle.png"
             alt=""
             height="80"
             width="80"
           />
           <p>TriDiamond</p>
           向下滑动
         </span>
       </div>
     </ Div > 
     < div class = "Center" > 
       < h1 > Pictures parallax effect DEMO </ h1 > 
       < the p- > 
         three drilling occurs why? We have to face a very awkward fact that, 
         from this point of view, 
         three drilling takes place, in the end need to how to do, not three drilling occurs, how will produce. 
         Why three drilling occurs? So, 
         in this difficult choice, I thought to want to, sleepless nights. 
         Locke said so inadvertently learned many tricks of things, that is, all of a sudden do not learn a lot. This inspired me 
         in this difficult choice, I thought to want to, sleepless nights. 
         Seneca said so inadvertently, real life, can only be achieved after a tough extraordinary struggle. This seems to answer my doubts. 
         I, for one, three drill meant to me, say that it is very important. 
         A clear understanding of how three drill in the end is a kind of existence is the key to solving all problems. 
         For me personally, not just three drill a big event, also could change my life.
         Summary, life, if three drill there, we have to consider the fact that it occurred. 
         So, in general, we must be sure to carefully think about it. After these discussions, 
         live, if three drill there, we have to consider the fact that it occurred. 
         And these are not entirely important, more important question is, 
         to make it clear, three drilling, in the end is how kind of existence. 
         Lei Feng said a philosophical words, their own lives to make others a more beautiful. This seems to answer my doubts. 
         I am also well thought out, think about this problem in every day and night. 
         The question Why? 
         Three drilling occurs, in the end need to how to do, not three drilling occurs, how will produce. 
         Napoleon Hill once said, do not wait, the time will never be just right. With these words, we have to be more careful look at this question: 
         So, 
         Michael · F · Staley said a philosophical words, the most challenging challenge than self-improvement. I hope you can properly understand this sentence. 
         La Rochefoucauld had mentioned, the only drawback we do not correct the weakness. Although very short sentence discourse, but to my imagination. 
         So, I, for one, three drill meant to me, say that it is very important. 
         From this perspective, after the above discussion, after the above discussion, 
         we have to face a very awkward fact that. 
       </ P > 
     </ div>
     <div class="parallax-img2">
       <div class="caption">
         <span>不同高度,不同感觉</span>
       </div>
     </div>
   </div>
 </body>

css code:

<style>
    * {
      padding: 0;
      margin: 0;
      font-family: Candara;
      box-sizing: border-box;
    }
    body,
    html {
      background: #202020;
      height: 100%;
    }
    .wrapper {
      height: 100%;
    }
    .parallax-img1 {
      height: 100%;
      background-image: url('http://ppe.oss-cn-shenzhen.aliyuncs.com/collections/182/7/thumb.jpg');
    }
    .parallax-img2 {
      min-height: 400px;
      background-image: url('http://ppe.oss-cn-shenzhen.aliyuncs.com/collections/182/5/thumb.jpg');
    }
    .parallax-img1,
    .parallax-img2 {
      position: relative;
      background-attachment: fixed;  //这里是关键代码
      background-position: center;
      background-repeat: no-repeat;
      background-size: cover;
    }
    .caption {
      position: absolute;
      top: 50%;
      transform: translateY(-50%);
      width: 100%;
      text-align: center;
      display: flex;
      justify-content: center;
    }
    .caption > span {
      background: rgb(32, 32, 32, 0.85);
      color: #82fcfd;
      padding: 18px 50px;
      font-size: 30px;
      border-radius: 16px;
    }
    .caption p {
      margin: 0 0 15px 0;
      padding: 0 0 15px 0;
      border-bottom: 2px solid #82fcfd;
    }
    .caption > span p {
      font-size: 40px;
    }
    p {
      margin: 15px;
      font-size: 1.1rem;
      padding: 1.5rem 5rem;
      color: #fff;
    }
    .center {
      width: 1200px;
      margin: 0 auto;
      color: #ddd;
    }
    h1 {
      text-align: center;
      margin: 3rem 0 0 0;
      color: #fff;
    }
  </style>

background-attachment: fixed main code for parallax, the position can be fixed background image, thereby achieving the effect of parallax.

Guess you like

Origin www.cnblogs.com/ZXH-null/p/12667586.html