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. You can use the CSS from another Pen by using it's URL and the proper URL extention.

+ 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

              
                詳しくはこちらの<a href="https://gmo-miyazaki-creators.com/coding/intersectionobserver/" target="_blank">ブログ記事</a>をご覧ください。<br>

<img src="" data-src="https://gmo-miyazaki-creators.com/wp-content/uploads/2022/04/intersectionobserver_img.jpg" alt="" class="lazyload">
<img src="" data-src="https://gmo-miyazaki-creators.com/wp-content/uploads/2022/04/intersectionobserver_img.jpg" alt="" class="lazyload">
<img src="" data-src="https://gmo-miyazaki-creators.com/wp-content/uploads/2022/04/intersectionobserver_img.jpg" alt="" class="lazyload">
<img src="" data-src="https://gmo-miyazaki-creators.com/wp-content/uploads/2022/04/intersectionobserver_img.jpg" alt="" class="lazyload">
<img src="" data-src="https://gmo-miyazaki-creators.com/wp-content/uploads/2022/04/intersectionobserver_img.jpg" alt="" class="lazyload">
<img src="" data-src="https://gmo-miyazaki-creators.com/wp-content/uploads/2022/04/intersectionobserver_img.jpg" alt="" class="lazyload">
<img src="" data-src="https://gmo-miyazaki-creators.com/wp-content/uploads/2022/04/intersectionobserver_img.jpg" alt="" class="lazyload">
<img src="" data-src="https://gmo-miyazaki-creators.com/wp-content/uploads/2022/04/intersectionobserver_img.jpg" alt="" class="lazyload">
<img src="" data-src="https://gmo-miyazaki-creators.com/wp-content/uploads/2022/04/intersectionobserver_img.jpg" alt="" class="lazyload">
<img src="" data-src="https://gmo-miyazaki-creators.com/wp-content/uploads/2022/04/intersectionobserver_img.jpg" alt="" class="lazyload">
<img src="" data-src="https://gmo-miyazaki-creators.com/wp-content/uploads/2022/04/intersectionobserver_img.jpg" alt="" class="lazyload">
<img src="" data-src="https://gmo-miyazaki-creators.com/wp-content/uploads/2022/04/intersectionobserver_img.jpg" alt="" class="lazyload">
<img src="" data-src="https://gmo-miyazaki-creators.com/wp-content/uploads/2022/04/intersectionobserver_img.jpg" alt="" class="lazyload">
<img src="" data-src="https://gmo-miyazaki-creators.com/wp-content/uploads/2022/04/intersectionobserver_img.jpg" alt="" class="lazyload">
              
            
!

CSS

              
                img {
  opacity: 0;
  height: 200px;
  margin: 10px;
  transition: 1s;
  display: block;
  
  &.lazyloaded {
    opacity: 1;
  }
}
              
            
!

JS

              
                //「lazyload」クラスがついている要素を取得
const lazyImages = document.querySelectorAll(".lazyload");
// IntersectionObserverに対応しているブラウザのみ、処理を実行
if ("IntersectionObserver" in window) {
	//オプションを設定
	const options = {
		root: null,
		rootMargin: "0px",
		threshold: 0.0
	}
	//監視内容
	const lazyImageObserver = new IntersectionObserver(function(entries, observer) {
		entries.forEach(function(entry) {
			// この要素が画面に入ってきた場合
			if (entry.isIntersecting) {
				var lazyImage = entry.target;
				if (lazyImage.dataset.hasOwnProperty("src")) {
					lazyImage.src = lazyImage.dataset.src;
					delete lazyImage.dataset.src;
				}
				// ロード済みのクラス「lazyloaded」を付加
				lazyImage.classList.add("lazyloaded");
				// この画像要素を観察対象から外す
				lazyImageObserver.unobserve(lazyImage);
			}
		});
	}, options);
	//監視開始
	lazyImages.forEach(function(lazyImage) {
		lazyImageObserver.observe(lazyImage);
	});
} else {
	//IntersectionObserverに対応していないブラウザの場合の処理
	lazyImages.forEach(function(lazyImage) {
		lazyImage.src = lazyImage.dataset.src;
		delete lazyImage.dataset.src;
		lazyImage.classList.add("lazyloaded");
	})
}
              
            
!
999px

Console