WEBデザインの勉強

WEB制作初心者が1から勉強するブログ。

SCROLLIFY

f:id:mmmmofu:20161027132147p:plain

決められた要素ごとにスクロールできるjQueryプラグイン

公式サイト

projects.lukehaas.me

デモはこちら

http://efu.sakura.ne.jp/web/scrollify/


ページャとスクロールボタンを設置

<!DOCTYPE html>
<html lang="ja">
<head>
  <meta charset="UTF-8">
  <title>SCROLLIFY</title>
  <link rel="stylesheet" href="css/style.css">
  <script src="http://code.jquery.com/jquery-1.11.1.min.js"></script>
  <script src="js/jquery.easing.1.3.js"></script>
  <script src="js/jquery.scrollify.js"></script>
  <script src="js/script.js"></script>
</head>
<body>
  <div>
    <div class="panel box1" data-section-name="panel1">
      <p>パネル1</p>
      <p class="scroll">
        <a href="#panel2"></a>
        <span class="arrow_01 arrow"></span>
        <span class="arrow_02 arrow"></span>
        <span class="text">scroll</span>
      </p>
    </div>
    <div class="panel box2" data-section-name="panel2">
      <p>パネル2</p>
      <p class="scroll">
        <a href="#panel3"></a>
        <span class="arrow_01 arrow"></span>
        <span class="arrow_02 arrow"></span>
        <span class="text">scroll</span>
      </p>
    </div>
    <div class="panel box3" data-section-name="panel3">
      <p>パネル3</p>
      <p class="scroll">
        <a href="#panel4"></a>
        <span class="arrow_01 arrow"></span>
        <span class="arrow_02 arrow"></span>
        <span class="text">scroll</span>
      </p>
    </div>
    <div class="panel box4"  data-section-name="panel4">
      <p>パネル4</p>
      <p class="end_text">END</p>
    </div>
  </div>
  <ul class="nav">
    <li class="active"><a href="#panel1"></a></li>
    <li><a href="#panel2"></a></li>
    <li><a href="#panel3"></a></li>
    <li><a href="#panel4"></a></li>
  </ul>
</body>
</html>
/* http://meyerweb.com/eric/tools/css/reset/
   v2.0 | 20110126
   License: none (public domain)
*/

html, body, div, span, applet, object, iframe,
h1, h2, h3, h4, h5, h6, p, blockquote, pre,
a, abbr, acronym, address, big, cite, code,
del, dfn, em, img, ins, kbd, q, s, samp,
small, strike, strong, sub, sup, tt, var,
b, u, i, center,
dl, dt, dd, ol, ul, li,
fieldset, form, label, legend,
table, caption, tbody, tfoot, thead, tr, th, td,
article, aside, canvas, details, embed,
figure, figcaption, footer, header, hgroup,
menu, nav, output, ruby, section, summary,
time, mark, audio, video {
  margin: 0;
  padding: 0;
  border: 0;
  font-size: 100%;
  font: inherit;
  vertical-align: baseline;
}
/* HTML5 display-role reset for older browsers */
article, aside, details, figcaption, figure,
footer, header, hgroup, menu, nav, section {
  display: block;
}
body {
  line-height: 1;
}
ol, ul {
  list-style: none;
}
blockquote, q {
  quotes: none;
}
blockquote:before, blockquote:after,
q:before, q:after {
  content: '';
  content: none;
}
table {
  border-collapse: collapse;
  border-spacing: 0;
}
body {
  font-family: "游ゴシック", YuGothic, "ヒラギノ角ゴ ProN W3", "Hiragino Kaku Gothic ProN", "メイリオ", Meiryo, "Helvetica Neue", Helvetica, Arial, sans-serif;
  font-weight: 500;
}

.panel {
  position: relative;
  width: 100%;
  height: 100%;
}

.panel p {
  font-size: 60px;
  color: #FFF;
  font-weight: bold;
  text-align: center;
  padding-top: 50px;
}

.panel .scroll {
  position: absolute;
  bottom: 50px;
  left: 0;
  right: 0;
  margin: auto;
  width: 100px;
  font-size: 12px;
  cursor: pointer;
  -webkit-transition: opacity .3s linear;
  -o-transition: opacity .3s linear;
  transition: opacity .3s linear;
}

.panel .scroll a {
  position: absolute;
  top: 0;
  left: 0;
  display: block;
  width: 100%;
  height: 100%;
}

.panel .scroll:hover {
  opacity: 0.6;
}

.panel .scroll .text {
  display: block;
  padding-top: 30px;
  color: #333;
}

.panel .scroll .arrow {
  display: block;
  width: 50px;
  height: 1px;
  background: #333;
}

.panel .scroll .arrow_01 {
  transform: rotate(45deg);
  margin-left: 5px;
}

.panel .scroll .arrow_02 {
  transform: rotate(-45deg);
  margin-left: 40px;
}

.panel .end_text {
  position: absolute;
  bottom: 50px;
  left: 0;
  width: 100%;
  text-align: center;
  font-size: 24px;
}

.box1 {
  background: #FFCFDF
}

.box2 {
  background: #FEFDCA;
}

.box3 {
  background: #E0F9B5;
}

.box4 {
  background: #A5DEE5;
}

.nav {
  position: fixed;
  top: 0;
  bottom: 0;
  margin: auto;
  right: 50px;
  height: 314px;

}

.nav li {
  cursor: pointer;
  margin: 50px 0;
}

.nav li a {
  display: block;
  width: 10px;
  height: 10px;
  border:3px solid #FFF;
  background: #333;
  border-radius: 50%;
}

.nav li a:hover {
  background: #F85F73;
}

.nav li.active a {
  background: #F85F73;
}
$(function(){
  $.scrollify({
    section : ".panel",
    before:function(i,panels) {
      var ref = panels[i].attr("data-section-name");
      $(".nav li.active").removeClass("active");
      $(".nav li").find("a[href=\"#" + ref + "\"]").parent().addClass("active");
    }
  });

  $(".nav li a, .scroll a").on("click",function() {
    $.scrollify.move($(this).attr("href"));
  });

});