JavaSctipt

【JavaScript】パララックス【Rellax.js】その③

CDN ⇒ header

<script src="https://cdnjs.cloudflare.com/ajax/libs/rellax/1.12.1/rellax.min.js"></script>

 

Javascript ⇒ footer

var rellax = new Rellax('.js-rellax', {
  center: true,
});

 

HTML

<div class="sample001">
  <div class="contents">
    <div class="js-rellax" data-rellax-speed="4">
      <p class="title">SAMPLE TITTLE</p>
      <p class="text">text text text text text text text text text text<br>text text text text text text text text text<br>text text text text text text text text</p>
      <a href="#">view more</a>
    </div>
  </div>
  <div class="contents">
    <div class="js-rellax" data-rellax-speed="4">
      <p class="title">SAMPLE TITTLE</p>
      <p class="text">text text text text text text text text text text<br>text text text text text text text text text<br>text text text text text text text text</p>
      <a href="#">view more</a>
    </div>
  </div>
  <div class="contents">
    <div class="js-rellax" data-rellax-speed="4">
      <p class="title">SAMPLE TITTLE</p>
      <p class="text">text text text text text text text text text text<br>text text text text text text text text text<br>text text text text text text text text</p>
      <a href="#">view more</a>
    </div>
  </div>
</div>

 

CSS

.sample001 .contents{
  height: 100vh;
  display: flex;
  justify-content: center;
  align-items: center;
  background-size: cover;
  background-position: center;
  background-repeat: no-repeat;
  background-attachment: fixed;
}

.sample001 .contents:nth-of-type(1){
  background-image: url(../img/rellax-sample3.jpg);
}

.sample001 .contents:nth-of-type(2){
  background-image: url(../img/rellax-sample4.jpg);
}

.sample001 .contents:nth-of-type(3){
  background-image: url(../img/rellax-sample5.jpg);
}

.sample001 .title{
  color: #fff;
  font-size: 30px;
  font-weight: bold;
  text-align: center;
  letter-spacing: 2px;
  margin-bottom: 10px;
}

.sample001 .text{
  color: #fff;
  font-size: 14px;
  text-align: center;
  padding: 0 20px;
  margin-bottom: 20px;
}

.sample001 a{
  background: rgba(255, 255, 255, 0.9);
  display: block;
  width: 200px;
  font-size: 18px;
  font-weight: bold;
  text-align: center;
  text-decoration: none;
  padding: 3px 0;
  margin: 0 auto;
}

@media screen and (min-width: 768px) {
  .sample001 .title{
    font-size: 50px;
    margin-bottom: 20px;
  }

  .sample001 .text{
    font-size: 18px;
  }

  .sample001 a{
    width: 220px;
    padding: 6px 0;
  }
}