Pen Settings

HTML

CSS

CSS Base

Vendor Prefixing

Add External Stylesheets/Pens

Any URL's added here will be added as <link>s in order, and before the CSS in the editor. If you link to another Pen, it will include the CSS from that Pen. If the preprocessor matches, it will attempt to combine them before processing.

+ 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

Save Automatically?

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

              
                <div class="crossfade-wrapper fadein-on-page-load">
  <div class="crossfade-animation fixed-background-image"></div>
  <div class="crossfade-animation fixed-background-image"></div>
  <div class="crossfade-animation fixed-background-image"></div>
  <div class="crossfade-animation fixed-background-image"></div>
</div>
              
            
!

CSS

              
                @charset "utf-8";

// フェードインさせる時間
$fade_in_delay:2;

// クロスフェードさせる画像の枚数
$number_of_image:4;

// 画像一枚あたりを表示させる時間(秒)
$presentation_time_for_one_image:3;

// クロスフェードさせるときの間隔(秒)
$duration_for_cross_fading:1;

// クロスフェードさせる画像のパス(cssファイルのディレクトリが基準)
$crossfade_images_path:'';

// クロスフェードさせる画像の名前
$crossfade_images:'http://lorempixel.com/1200/800/cats/1/', 'http://lorempixel.com/1200/800/cats/2/', 'http://lorempixel.com/1200/800/cats/3/', 'http://lorempixel.com/1200/800/cats/4/';


//----------------------------------------------------------------------
//
// CSS3アニメーションのプロパティにベンダープレフィックスをつけるためのmixin
//
// Reference:
// http://caniuse.com/#feat=css-animation
//
//----------------------------------------------------------------------
@mixin css3-animation( $property, $value ) {
  @each $prefix in -webkit-, '' {
    #{$prefix}#{$property}: $value;
  }
}

//----------------------------------------------------------------------
//
// CSS3アニメーションのkeyframeに対してベンダープレフィックスをつけるmixin
//
// Reference:
// http://caniuse.com/#feat=css-animation
//
//----------------------------------------------------------------------
@mixin css3-keyframes($name) {
  @-webkit-keyframes #{$name} {
    @content; 
  }
  @keyframes #{$name} {
    @content;
  } 
}

//----------------------------------------------------------------------
//
// keyframesでbackground-imageを切り替えるのは2015年4月現在でSafariとChromeのみ、IEとFirefoxは未実装なため、
// 背景画像の枚数分だけ要素を用意してopacityを変更することでクロスフェードを実現している。
//
//----------------------------------------------------------------------

.fadein-on-page-load {
  @include css3-animation( animation, fadeinOnPageLoad #{$fade_in_delay}s );
}

@include css3-keyframes( fadeinOnPageLoad ) {
  from { opacity: 0; }
  to   { opacity: 1; }
}

// アニメーションの間隔
$animation_delay:$presentation_time_for_one_image+$duration_for_cross_fading;

// トータルのアニメーション間隔
$total_animation_delay:$animation_delay*$number_of_image;

// 背景を固定させる要素につけるスタイル
// 必要であれば各属性の値を変更してください
.fixed-background-image {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background-repeat: no-repeat;
  background-size: cover;
  background-position: center center;
}

@include css3-keyframes( crossFade ) {
  0% { opacity:1; }
  #{$presentation_time_for_one_image/$total_animation_delay*100%} { opacity:1; }
  #{100%/$number_of_image} { opacity:0; }
  #{100% - $duration_for_cross_fading/$total_animation_delay*100%} { opacity:0; }
  100% { opacity:1; }
}

.crossfade-wrapper {
  @for $i from 1 through $number_of_image {
    div:nth-of-type(#{$i}) {
      background-image: url( #{$crossfade_images_path}#{nth($crossfade_images, $number_of_image - $i + 1)} );
      @include css3-animation( animation-delay, #{$total_animation_delay - $i*$animation_delay}s );
    }
  }
}

.crossfade-animation {
  @include css3-animation( animation, crossFade #{$total_animation_delay}s infinite );
}
              
            
!

JS

              
                
              
            
!
999px

Console