jQuery_滾軸移動改變Class

In this example below you will see how to do a jQuery_滾軸移動改變Class with some HTML / CSS and Javascript

Thumbnail
This awesome code was written by mrjohnson, you can see more from this user in the personal repository.
You can find the original code on Codepen.io
Copyright mrjohnson ©
  • HTML
  • CSS
  • JavaScript
    <div class="wrap">
</div>
<div class="wrap2">
  <div class="next"></div>
  <div class="prev"></div>
</div>

/*Downloaded from https://www.codeseek.co/mrjohnson/jquery_andx6efeandx8ef8andx79fbandx52d5andx6539andx8b8aclass-mWBzBd */
    body{
  margin: 0;
  padding: 0;
}
.wrap{
 height: 200px;
  width: 500px;
  background-color:#eee;
  position: relative; 
  margin:0 auto;
}
.wrap2{
  height: 1000px;
  width: 500px;
  background-color:#777;
  position: relative;
  margin:0 auto;
}
.next, .prev{
  background-image:url("https://cdn0.iconfinder.com/data/icons/arrows-android-l-lollipop-icon-pack/24/next-128.png");
  background-repeat:no-repeat;
  background-size:cover;
  border-radius:50%;
  width: 100px;
  height: 100px;
  background-color:rgba(0,0,0,.3);
  position: absolute;
  top: 50px;
  right: -50px;
  opacity:0;
  transition:opacity .3s;
}
.prev{
  left:-50px;
  transform:rotate(180deg);
}
.wrap2:hover .prev, .wrap2:hover .next{
  opacity:1;
}
.wrap2 .active{
  position: fixed;
  top:50px;
  left:50%;
}
.wrap2 .next.active{
  margin-left:200px;
}
.wrap2 .prev.active{
  margin-left:-300px;
}



/*Downloaded from https://www.codeseek.co/mrjohnson/jquery_andx6efeandx8ef8andx79fbandx52d5andx6539andx8b8aclass-mWBzBd */
    $(function() {
  $(window).scroll(function() {
    if ($(this).scrollTop() > 200) {
      $(".wrap2").children("div").addClass("active")
    } else {
      $(".wrap2").children("div").removeClass("active")
    }
  })
})

Comments