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 id="container">
	  <section id="one">
		<h1>スクロールすると写真が表示するアニメーション01</h1>
		<div class="cover-slide hover-darken">
			<img class="img-zoom" src="https://dl.dropbox.com/s/q6uyk0fartfzljt/3d-contemporary-living-room-interior-and-modern-furniture.jpg?dl=0" alt="">
		</div>
		<div class="cover-slide hover-darken">
			<img class="img-zoom" src="https://dl.dropbox.com/s/q6uyk0fartfzljt/3d-contemporary-living-room-interior-and-modern-furniture.jpg?dl=0" alt="">
		</div>
		<div class="cover-slide hover-darken">
			<img class="img-zoom" src="https://dl.dropbox.com/s/q6uyk0fartfzljt/3d-contemporary-living-room-interior-and-modern-furniture.jpg?dl=0" alt="">
		</div>
		<div class="cover-slide hover-darken">
			<img class="img-zoom" src="https://dl.dropbox.com/s/q6uyk0fartfzljt/3d-contemporary-living-room-interior-and-modern-furniture.jpg?dl=0" alt="">
		</div>
		<p class="rit"><a href='https://jp.freepik.com/photos/flower'>Kjpargeter - jp.freepik.com によって作成された flower 写真</a></p>
	  </section>
	  <section id="two">
		<h1>スクロールすると画像がふわっと表示されるアニメーション</h1>
		<div class="cover-slide hover-darken">
			<img class="img-zoom" src="https://dl.dropbox.com/s/q6uyk0fartfzljt/3d-contemporary-living-room-interior-and-modern-furniture.jpg?dl=0" alt="">
		</div>
		<div class="cover-slide hover-darken">
			<img class="img-zoom" src="https://dl.dropbox.com/s/q6uyk0fartfzljt/3d-contemporary-living-room-interior-and-modern-furniture.jpg?dl=0" alt="">
		</div>
		<div class="cover-slide hover-darken">
			<img class="img-zoom" src="https://dl.dropbox.com/s/q6uyk0fartfzljt/3d-contemporary-living-room-interior-and-modern-furniture.jpg?dl=0" alt="">
		</div>
		<div class="cover-slide hover-darken">
			<img class="img-zoom" src="https://dl.dropbox.com/s/q6uyk0fartfzljt/3d-contemporary-living-room-interior-and-modern-furniture.jpg?dl=0" alt="">
		</div>
		<p class="rit"><a href='https://jp.freepik.com/photos/background'>Topntp26 - jp.freepik.com によって作成された background 写真</a></p>
	  </section>
	</div>
	<script src="js/scroll-polyfill.js"></script>
    <script src="js/scroll.js"></script>
    <script src="js/main.js"></script>

              
            
!

CSS

              
                img {
  max-width: 100%;
  vertical-align: bottom;
}

h1 {
  font-size: 16px;
  margin: 25px 0 15px;
}

#container {
  width: 750px;
  margin: auto;
}

#one .cover-slide {
  position: relative;
  overflow: hidden;
  margin-bottom: 50px;
}

#one .cover-slide::after {
  content: "";
  position: absolute;
  z-index: 2;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background-color: #eaebe6;
  opacity: 0;
}

#one .cover-slide.inview::after {
  opacity: 1;
  -webkit-animation-name: kf-cover-slide;
          animation-name: kf-cover-slide;
  -webkit-animation-duration: 1.6s;
          animation-duration: 1.6s;
  -webkit-animation-timing-function: ease-in-out;
          animation-timing-function: ease-in-out;
  -webkit-animation-delay: 0s;
          animation-delay: 0s;
  -webkit-animation-iteration-count: 1;
          animation-iteration-count: 1;
  -webkit-animation-direction: normal;
          animation-direction: normal;
  -webkit-animation-fill-mode: forwards;
          animation-fill-mode: forwards;
}

@-webkit-keyframes kf-cover-slide {
  0% {
    -webkit-transform-origin: left;
    transform-origin: left;
    -webkit-transform: scaleX(0);
    transform: scaleX(0);
  }
  50% {
    -webkit-transform-origin: left;
    transform-origin: left;
    -webkit-transform: scaleX(1);
    transform: scaleX(1);
  }
  50.1% {
    -webkit-transform-origin: right;
    transform-origin: right;
    -webkit-transform: scaleX(1);
    transform: scaleX(1);
  }
  100% {
    -webkit-transform-origin: right;
    transform-origin: right;
    -webkit-transform: scaleX(0);
    transform: scaleX(0);
  }
}

@keyframes kf-cover-slide {
  0% {
    -webkit-transform-origin: left;
    transform-origin: left;
    -webkit-transform: scaleX(0);
    transform: scaleX(0);
  }
  50% {
    -webkit-transform-origin: left;
    transform-origin: left;
    -webkit-transform: scaleX(1);
    transform: scaleX(1);
  }
  50.1% {
    -webkit-transform-origin: right;
    transform-origin: right;
    -webkit-transform: scaleX(1);
    transform: scaleX(1);
  }
  100% {
    -webkit-transform-origin: right;
    transform-origin: right;
    -webkit-transform: scaleX(0);
    transform: scaleX(0);
  }
}

#one .img-zoom, #one .bg-img-zoom {
  opacity: 0;
}

#one .inview .img-zoom, #one .inview .bg-img-zoom {
  opacity: 1;
  transition: -webkit-transform 0.3s ease;
  transition: transform 0.3s ease;
  transition: transform 0.3s ease, -webkit-transform 0.3s ease;
  -webkit-animation-name: kf-img-show;
          animation-name: kf-img-show;
  -webkit-animation-duration: 1.6s;
          animation-duration: 1.6s;
  -webkit-animation-timing-function: ease-in-out;
          animation-timing-function: ease-in-out;
  -webkit-animation-delay: 0s;
          animation-delay: 0s;
  -webkit-animation-iteration-count: 1;
          animation-iteration-count: 1;
  -webkit-animation-direction: normal;
          animation-direction: normal;
  -webkit-animation-fill-mode: none;
          animation-fill-mode: none;
}

#one .inview .img-zoom:hover, #one .inview .bg-img-zoom:hover {
  -webkit-transform: scale(1.05);
  transform: scale(1.05);
}

@-webkit-keyframes kf-img-show {
  0% {
    opacity: 0;
  }
  50% {
    opacity: 0;
  }
  50.1% {
    opacity: 1;
    -webkit-transform: scale(1.5);
    transform: scale(1.5);
  }
  100% {
    opacity: 1;
  }
}

@keyframes kf-img-show {
  0% {
    opacity: 0;
  }
  50% {
    opacity: 0;
  }
  50.1% {
    opacity: 1;
    -webkit-transform: scale(1.5);
    transform: scale(1.5);
  }
  100% {
    opacity: 1;
  }
}

#one .hover-darken::before {
  content: "";
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  z-index: 1;
  transition: background-color 0.3s ease;
  pointer-events: none;
  -webkit-animation-name: kf-img-show;
          animation-name: kf-img-show;
  -webkit-animation-duration: 1.6s;
          animation-duration: 1.6s;
  -webkit-animation-timing-function: ease-in-out;
          animation-timing-function: ease-in-out;
  -webkit-animation-delay: 0s;
          animation-delay: 0s;
  -webkit-animation-iteration-count: 1;
          animation-iteration-count: 1;
  -webkit-animation-direction: normal;
          animation-direction: normal;
  -webkit-animation-fill-mode: none;
          animation-fill-mode: none;
}

#one .hover-darken:hover::before {
  background-color: rgba(0, 0, 0, 0.4);
}

#one .bg-img-zoom {
  background-image: url(images/image-1.jpg);
  background-repeat: no-repeat;
  background-position: center;
  background-size: cover;
  width: 100%;
}

#one .img-bg50 {
  position: relative;
}

#one .img-bg50::before {
  display: block;
  content: '';
  padding-top: 50%;
}

#two .cover-slide {
  margin: 0 auto 100px;
}

#two .img-zoom, #two #one .bg-img-zoom, #one #two .bg-img-zoom {
  opacity: 0;
  -webkit-transform: translateY(-50px);
  transform: translateY(-50px);
  transition-duration: 2s;
}

#two .inview .img-zoom, #two .inview #one .bg-img-zoom, #one #two .inview .bg-img-zoom {
  opacity: 1;
  -webkit-transform: translateY(0);
  transform: translateY(0);
}

#two .inview .img-zoom:hover, #two .inview #one .bg-img-zoom:hover, #one #two .inview .bg-img-zoom:hover {
  -webkit-transform: scale(1.05);
  transform: scale(1.05);
}

@media only screen and (max-width: 640px) {
  #container {
    width: 280px;
    margin: auto;
  }
}
/*# sourceMappingURL=style.css.map */
              
            
!

JS

              
                
class ScrollObserver {
	constructor(els, cb, options) {
		this.els = document.querySelectorAll(els);
		//オプションの設定
		const defaultOptions = {
			root: null, //交差点の設定
			rootMargin: "0px", //交差点の位置を設定
			threshold: 0, //交差点の進行方向の上部を選択
			once: true
		};
		this.cb = cb;
		this.options = Object.assign(defaultOptions, options);
		//this.once = this.options.once;
		this._init();
	}
	_init() {
		const callback = function (entries, observer) {

			//entriesの配列--entry/entries
			entries.forEach(entry => {
				//entryに要素があれば処理を行う
				if (entry.isIntersecting) {
					this.cb(entry.target, true);
					//一度だけ読み込む場合
					//if(this.once) {
					//observer.unobserve(entry.target);
					//}
				} else {
					this.cb(entry.target, false);
				}
			});
		};
		//監視している対象が交差した時に起動する
		this.io = new IntersectionObserver(callback.bind(this), this.options);

		//使用できないブラウザのため
		// @see https://github.com/w3c/IntersectionObserver/tree/master/polyfill
		//100mmごとに監視する
		//this.io.POLL_INTERVAL = 100;

		//複数から一つづつ取り出して監視対象
		this.els.forEach(el => this.io.observe(el));
	}
	//不用になったら解除する
	//destory() {
		//this.io.disconnect();
	//}
}

document.addEventListener('DOMContentLoaded', function () {

	const cb = function (el, isIntersecting) {
		if (isIntersecting) {
			el.classList.add('inview');
		}
		//要素が画面を外れたらクラスを外す
		else {
			el.classList.remove('inview');
		}
	}

	const so = new ScrollObserver('.cover-slide', cb);
});

              
            
!
999px

Console