Pen Settings

HTML

CSS

CSS Base

Vendor Prefixing

Add External Stylesheets/Pens

Any URLs added here will be added as <link>s in order, and before the CSS in the editor. You can use the CSS from another Pen by using its URL and the proper URL extension.

+ add another resource

JavaScript

Babel includes JSX processing.

Add External Scripts/Pens

Any URL's added here will be added as <script>s in order, and run before the JavaScript in the editor. You can use the URL of any other Pen and it will include the JavaScript from that Pen.

+ add another resource

Packages

Add Packages

Search for and use JavaScript packages from npm here. By selecting a package, an import statement will be added to the top of the JavaScript editor for this package.

Behavior

Auto Save

If active, Pens will autosave every 30 seconds after being saved once.

Auto-Updating Preview

If enabled, the preview panel updates automatically as you code. If disabled, use the "Run" button to update.

Format on Save

If enabled, your code will be formatted when you actively save your Pen. Note: your code becomes un-folded during formatting.

Editor Settings

Code Indentation

Want to change your Syntax Highlighting theme, Fonts and more?

Visit your global Editor Settings.

HTML

              
                <body>
<div class="mv">
      <a class="item js-hover" href="javascript:void(0)">
        <div class="inner"></div>
      </a>
      <a class="item js-hover" href="javascript:void(0)">
        <div class="inner"></div>
      </a>
      <a class="item js-hover" href="javascript:void(0)">
        <div class="inner"></div>
      </a>
      <a class="item js-hover" href="javascript:void(0)">
        <div class="inner"></div>
      </a>
      <a class="item js-hover" href="javascript:void(0)">
        <div class="inner"></div>
      </a>
      <a class="item js-hover" href="javascript:void(0)">
        <div class="inner"></div>
      </a>
      <a class="item js-hover" href="javascript:void(0)">
        <div class="inner"></div>
      </a>
      <a class="item js-hover" href="javascript:void(0)">
        <div class="inner"></div>
      </a>
      <a class="item js-hover" href="javascript:void(0)">
        <div class="inner"></div>
      </a>
      <a class="item js-hover" href="javascript:void(0)">
        <div class="inner"></div>
      </a>
    </div>
</body>
              
            
!

CSS

              
                * {
        box-sizing: border-box;
        margin: 0;
        padding: 0;
      }
      body, html {
        width: 100%;
        height: 100%;
        background-color: #f2f2f2;
      }
      .mv {
        position: absolute;
        top: 0;
        left: 0;
        width: 100%;
        height: 100%;
        overflow: hidden;
        display: flex;
        flex-direction: column;
        padding: .2vw;
      }
      .mv > .item {
        position: relative;
        display: block;
        width: 100%;
        background-color: #83dfed;
        flex-grow: 1;
      }
      .mv > .item:not(:last-child) {
        margin-bottom: .2vw;
      }
      .mv > .item > .inner {
        position: absolute;
        top: 0;
        left: 0;
        width: 100%;
        height: 100%;
        background-color: #417dde;
        transform-origin: 0% 50%;
      }
              
            
!

JS

              
                

// -----------------------------------------
// Hover要素管理クラス
// -----------------------------------------
HoverMgr = function(el) {

  // 操作する要素
  this.el = el;

  // アニメーションさせる要素
  this.tg = this.el.find('> .inner');

  // マウス乗ってるかどうか
  this.isOver = false;

  // アニメーション中かどうか
  this.isPlaying = false;

};

// 初期化
HoverMgr.prototype.init = function() {

  this.el.on('mouseover', this._eRollOver.bind(this)).on('mouseout', this._eRollOut.bind(this));

  TweenMax.set(this.tg, {
    scaleX:0
  });

};

// ロールオーバー
HoverMgr.prototype._eRollOver = function() {

  this.isOver = true;
  if(!this.isPlaying) {
    this._startRollOver();
  }

};

// ロールアウト
HoverMgr.prototype._eRollOut = function(e) {

  this.isOver = false;
  if(!this.isPlaying) {
    this._startRollOut();
  }

};

// ロールオーバーのアニメーション
HoverMgr.prototype._startRollOver = function() {

  this.isPlaying = true;
  TweenMax.to(this.tg, 0.6, {
    scaleX:1,
    ease:Expo.easeOut,
    onComplete:this._eCompleteRollOver.bind(this)
  });

};

// ロールアウトのアニメーション
HoverMgr.prototype._startRollOut = function() {

  this.isPlaying = true;
  TweenMax.to(this.tg, 0.5, {
    scaleX:0,
    ease:Expo.easeInOut,
    onComplete:this._eCompleteRollOut.bind(this)
  });

};

// ロールオーバーのアニメーション終わり
HoverMgr.prototype._eCompleteRollOver = function() {

  this.isPlaying = false;
  if(!this.isOver) {
    this._startRollOut();
  }

};

// ロールアウトのアニメーション終わり
HoverMgr.prototype._eCompleteRollOut = function() {

  this.isPlaying = false;
  if(this.isOver) {
    this._startRollOver();
  }

};
// -----------------------------------------





// 初期設定
init();
function init() {

  $('.js-hover').each(function(i,e) {

    var o = new HoverMgr($(e));
    o.init();

  });

  update();

}

// 毎フレーム実行
// 今回は無視
window.requestAnimationFrame(update);
function update() {
  window.requestAnimationFrame(update);
}



// ----------------------------------------
// 度からラジアンに変換
// @val : 度
// ----------------------------------------
function radian(val) {
  return val * Math.PI / 180;
}

// ----------------------------------------
// ラジアンから度に変換
// @val : ラジアン
// ----------------------------------------
function degree(val) {
  return val * 180 / Math.PI;
}

// ----------------------------------------
// minからmaxまでランダム
// ----------------------------------------
function random(min, max) {
  return Math.random() * (max - min) + min;
}

// ----------------------------------------
// 範囲変換
// @val     : 変換したい値
// @toMin   : 変換後の最小値
// @toMax   : 変換後の最大値
// @fromMin : 変換前の最小値
// @fromMax : 変換前の最大値
// ----------------------------------------
function map(val, toMin, toMax, fromMin, fromMax) {
  if(val <= fromMin) {
    return toMin;
  }
  if(val >= fromMax) {
    return toMax;
  }
  p = (toMax - toMin) / (fromMax - fromMin);
  return ((val - fromMin) * p) + toMin;
}

              
            
!
999px

Console