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

              
                <div class="container">
  <div class="main-img js-main-img">
    <img
      src="https://junpei-sugiyama.com/wp-content/uploads/2021/01/dog01.jpg"
    />
  </div>
  <ul class="sub-img js-sub-img">
    <li class="current"><!-- アクティブな画像の枠線を変更 -->
      <img
        src="https://junpei-sugiyama.com/wp-content/uploads/2021/01/dog01.jpg"
      />
    </li>
    <li>
      <img
        src="https://junpei-sugiyama.com/wp-content/uploads/2021/01/dog02.jpg"
      />
    </li>
    <li>
      <img
        src="https://junpei-sugiyama.com/wp-content/uploads/2021/01/dog03.jpg"
      />
    </li>
  </ul>
</div>
              
            
!

CSS

              
                .container {
  margin: 50px auto 0;
  max-width: 500px;
}
.main-img {
  height: 334px;
  width: 100%;
}
.main-img img {
  height: auto;
  width: 100%;
}
.sub-img {
  display: flex;
  margin-top: 10px;
}
.sub-img li {
  margin-right: 2%;
  width: calc(96% / 3);
}
.sub-img li:nth-child(3n) {
  margin-right: 0;
}
.sub-img li img {
  border: 2px solid transparent;
  transition: border .5s;
}
.sub-img img {
  cursor: pointer;
  width: 100%;
}
/* アクティブな画像の枠線を変更 */
.sub-img li.current img {
  border: 2px solid red;
  transition: border .5s;
}
              
            
!

JS

              
                $(function () {
  $(".js-sub-img img").on("click", function () {
    //mainに切り替えるimgのsrc取得
    img = $(this).attr("src");
    //currentクラス付け替え(枠線などを変えたい時に)
    $(".js-sub-img li").removeClass("current");
    $(this).parent().addClass("current");
    //fadeOutできたらsrc変更してfadeIn
    $(".js-main-img img").fadeOut(500, function () {
      $(".js-main-img img")
        .attr("src", img)
        .on("load", function () {
          $(this).fadeIn(500);
        });
    });
  });
});
              
            
!
999px

Console