WEBデザインの勉強

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

ループアニメーション

f:id:mmmmofu:20161012123747p:plain

デモはこちら
http://efu.sakura.ne.jp/web/loop/

velocityjs.org

HTML

<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <title>Velocity.jsでループアニメーション</title>
  <link rel="stylesheet" href="css/style.css">
  <script src="http://code.jquery.com/jquery-1.11.1.min.js"></script>
  <script src="js/velocity.min.js"></script>
  <script src="js/script.js"></script>
</head>
<body>
  <div class="pic_items">
    <div class="pic_item_1"><img src="img/ph1.jpg" alt=""></div>
    <div class="pic_item_2"><img src="img/ph2.jpg" alt=""></div>
    <div class="pic_item_3"><img src="img/ph3.jpg" alt=""></div>
    <div class="pic_item_4"><img src="img/ph4.jpg" alt=""></div>
    <div class="pic_item_5"><img src="img/ph5.jpg" alt=""></div>
    <div class="pic_item_6"><img src="img/ph6.jpg" alt=""></div>
    <div class="pic_item_7"><img src="img/ph7.jpg" alt=""></div>
    <div class="pic_item_8"><img src="img/ph8.jpg" alt=""></div>
    <div class="pic_item_9"><img src="img/ph9.jpg" alt=""></div>
    <div class="pic_item_10"><img src="img/ph10.jpg" alt=""></div>
  </div>
</body>
</html>

CSS

/* 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;
}

img {
  width: 100%;
}
body {
  background: #fff;
}
.pic_items {
  position: relative;
  width: 960px;
  height: 400px;
  margin: 50px auto 0;
  overflow: hidden;
  background: #000;
}

.pic_item_10 {
  position: absolute;
  top: 10px;
  left: 3%;
  width: 280px;
}

.pic_item_9 {
  position: absolute;
  top: 100px;
  left: 50%;
  width: 260px;
}

.pic_item_8 {
  position: absolute;
  top: 200px;
  left: 80%;
  width: 240px;
}

.pic_item_7 {
  position: absolute;
  top: 150px;
  left: 70%;
  width: 220px;
  -webkit-filter: blur(1px);
  -ms-filter: blur(1px);
  filter: blur(1px);
}

.pic_item_6 {
  position: absolute;
  top: 1px;
  left: 90%;
  width: 160px;
  -webkit-filter: blur(1px);
  -ms-filter: blur(1px);
  filter: blur(1px);
}

.pic_item_5 {
  position: absolute;
  top: 250px;
  left: 20%;
  width: 140px;
  -webkit-filter: blur(2px);
  -ms-filter: blur(2px);
  filter: blur(2px);
}

.pic_item_4 {
  position: absolute;
  top: 100px;
  left: 30%;
  width: 120px;
  -webkit-filter: blur(3px);
  -ms-filter: blur(3px);
  filter: blur(3px);
}

.pic_item_3 {
  position: absolute;
  top: 230px;
  left: 20%;
  width: 90px;
  -webkit-filter: blur(5px);
  -ms-filter: blur(5px);
  filter: blur(5px);
}

.pic_item_2 {
  position: absolute;
  top: 10px;
  left: 70%;
  width: 70px;
  -webkit-filter: blur(5px);
  -ms-filter: blur(5px);
  filter: blur(5px);
}

.pic_item_1 {
  position: absolute;
  top: 200px;
  left: 40%;
  width: 60px;
  -webkit-filter: blur(5px);
  -ms-filter: blur(5px);
  filter: blur(5px);
}

JS

$(function(){
  var _loop1 = function _loop1() {
    $(".pic_item_1").velocity({ top: '-39.97px' }, { duration: 19000, easing: 'linear', complete: function complete() {
        $(".pic_item_1").css({ 'top': '400px' });
        _loop1();
      }
    });
  }
  var _loop2 = function _loop2(){
    $(".pic_item_2").velocity({ top: '-49px' }, { duration: 18000, easing: 'linear', complete: function complete() {
        $(".pic_item_2").css({ 'top': '400px' });
        _loop2();
      }
    });
  }
  var _loop3 = function _loop3(){
    $(".pic_item_3").velocity({ top: '-62px' }, { duration: 17000, easing: 'linear', complete: function complete() {
        $(".pic_item_3").css({ 'top': '400px' });
        _loop3();
      }
    });
  }
  var _loop4 = function _loop4(){
    $(".pic_item_4").velocity({ top: '-82px' }, { duration: 16000, easing: 'linear', complete: function complete() {
        $(".pic_item_4").css({ 'top': '400px' });
        _loop3();
      }
    });
  }
  var _loop5 = function _loop5(){
    $(".pic_item_5").velocity({ top: '-81px' }, { duration: 15000, easing: 'linear', complete: function complete() {
        $(".pic_item_5").css({ 'top': '400px' });
        _loop5();
      }
    });
  }
  var _loop6 = function _loop6(){
    $(".pic_item_6").velocity({ top: '-90px' }, { duration: 14000, easing: 'linear', complete: function complete() {
        $(".pic_item_6").css({ 'top': '400px' });
        _loop6();
      }
    });
  }
  var _loop7 = function _loop7(){
    $(".pic_item_7").velocity({ top: '-149px' }, { duration: 13000, easing: 'linear', complete: function complete() {
        $(".pic_item_7").css({ 'top': '400px' });
        _loop7();
      }
    });
  }
  var _loop8 = function _loop8(){
    $(".pic_item_8").velocity({ top: '-162px' }, { duration: 12000, easing: 'linear', complete: function complete() {
        $(".pic_item_8").css({ 'top': '400px' });
        _loop8();
      }
    });
  }
  var _loop9 = function _loop9(){
    $(".pic_item_9").velocity({ top: '-175px' }, { duration: 11000, easing: 'linear', complete: function complete() {
        $(".pic_item_9").css({ 'top': '400px' });
        _loop9();
      }
    });
  }
  var _loop10 = function _loop10(){
    $(".pic_item_10").velocity({ top: '-189px' }, { duration: 10000, easing: 'linear', complete: function complete() {
        $(".pic_item_10").css({ 'top': '400px' });
        _loop10();
      }
    });
  }

  $(window).on('load', function(){
    _loop1();
    _loop2();
    _loop3();
    _loop4();
    _loop5();
    _loop6();
    _loop7();
    _loop8();
    _loop9();
    _loop10();
  });
});