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

              
                <h1 style="text-align:center;font-family:Arial;font-weight: 300;">Basic jQuery Gallery</h1>

<div class="random-container" style="height: 100%;">
  
  <div class="kun-gallery">
    <ul>
      <li>
        <a class="image-1" style="background-image:url(https://images.unsplash.com/photo-1456425731181-2152d80d946c?ixlib=rb-0.3.5&q=85&fm=jpg&crop=entropy&cs=srgb&ixid=eyJhcHBfaWQiOjE0NTg5fQ&s=cdbb5e75e10f9a41669c37a87ffa9b7e)"></a>
      </li>
      <li>
        <a class="image-2" style="background-image:url(https://images.unsplash.com/photo-1504333638930-c8787321eee0?ixlib=rb-0.3.5&q=85&fm=jpg&crop=entropy&cs=srgb&ixid=eyJhcHBfaWQiOjE0NTg5fQ&s=316d2b468a6828578e6339fa448962ff);"></a></li>
      <li>
        <a class="image-3" style="background-image:url(https://images.unsplash.com/photo-1518457607834-6e8d80c183c5?ixlib=rb-0.3.5&q=85&fm=jpg&crop=entropy&cs=srgb&ixid=eyJhcHBfaWQiOjE0NTg5fQ&s=6a1745a2db93c684598393b35978c1e2)">
      </a>
      </li>
      <li>
        <a class="image-4" style="background-image:url(https://images.unsplash.com/photo-1475776408506-9a5371e7a068?ixlib=rb-0.3.5&q=85&fm=jpg&crop=entropy&cs=srgb&ixid=eyJhcHBfaWQiOjE0NTg5fQ&s=0be39f82a641962bb335c13ea2b0d3d6)">
      </a>
      </li>
      <li>
        <a class="image-5" style="background-image:url(https://images.unsplash.com/photo-1476041026529-411f6ae1de3e?ixlib=rb-0.3.5&q=85&fm=jpg&crop=entropy&cs=srgb&ixid=eyJhcHBfaWQiOjE0NTg5fQ&s=e14e45dcc6ca73053ae41e8121e599a6)">
      </a>
      </li>
      <li>
        <a class="image-6" style="background-image:url(https://images.unsplash.com/photo-1498713301984-508015049dc1?ixlib=rb-0.3.5&q=85&fm=jpg&crop=entropy&cs=srgb&ixid=eyJhcHBfaWQiOjE0NTg5fQ&s=feddb1d98ee6bf699cbdb7410f817a06)">
      </a>
      </li>
      <li>
        <a class="image-7" style="background-image:url(https://images.unsplash.com/photo-1522151501326-e0dc6eb350e1?ixlib=rb-0.3.5&q=85&fm=jpg&crop=entropy&cs=srgb&ixid=eyJhcHBfaWQiOjE0NTg5fQ&s=838524a7e5b88ab7de5d54d0342b3d83)">
      </a>
      </li>
      <li>
        <a class="image-8" style="background-image:url(https://images.unsplash.com/photo-1520720810040-f85066da6d93?ixlib=rb-0.3.5&q=85&fm=jpg&crop=entropy&cs=srgb&ixid=eyJhcHBfaWQiOjE0NTg5fQ&s=1b8b19ca158ac5b3bda2681ae833e5b6)">
      </a>
      </li>
    </ul>
  </div>

  <!------------------------- KUN LIGHTBOX ---------------------------->
  
  <div class="gallery-container">
    <div class="kun-modal"></div>
    <div class="left-arrow"> < </div>
    <div class="right-arrow"> > </div>
    <div class="close-icon"> x </div>
    <div class="kun-lightbox">

          <img class="image-1" src="https://images.unsplash.com/photo-1456425731181-2152d80d946c?ixlib=rb-0.3.5&q=85&fm=jpg&crop=entropy&cs=srgb&ixid=eyJhcHBfaWQiOjE0NTg5fQ&s=cdbb5e75e10f9a41669c37a87ffa9b7e" />

          <img class="image-2" src="https://images.unsplash.com/photo-1504333638930-c8787321eee0?ixlib=rb-0.3.5&q=85&fm=jpg&crop=entropy&cs=srgb&ixid=eyJhcHBfaWQiOjE0NTg5fQ&s=316d2b468a6828578e6339fa448962ff" />

          <img class="image-3" src="https://images.unsplash.com/photo-1518457607834-6e8d80c183c5?ixlib=rb-0.3.5&q=85&fm=jpg&crop=entropy&cs=srgb&ixid=eyJhcHBfaWQiOjE0NTg5fQ&s=6a1745a2db93c684598393b35978c1e2" />

          <img class="image-4" src="https://images.unsplash.com/photo-1475776408506-9a5371e7a068?ixlib=rb-0.3.5&q=85&fm=jpg&crop=entropy&cs=srgb&ixid=eyJhcHBfaWQiOjE0NTg5fQ&s=0be39f82a641962bb335c13ea2b0d3d6" />

          <img class="image-5" src="https://images.unsplash.com/photo-1476041026529-411f6ae1de3e?ixlib=rb-0.3.5&q=85&fm=jpg&crop=entropy&cs=srgb&ixid=eyJhcHBfaWQiOjE0NTg5fQ&s=e14e45dcc6ca73053ae41e8121e599a6" />

          <img class="image-6" src="
https://images.unsplash.com/photo-1498713301984-508015049dc1?ixlib=rb-0.3.5&q=85&fm=jpg&crop=entropy&cs=srgb&ixid=eyJhcHBfaWQiOjE0NTg5fQ&s=feddb1d98ee6bf699cbdb7410f817a06" />

          <img class="image-7" src="https://images.unsplash.com/photo-1522151501326-e0dc6eb350e1?ixlib=rb-0.3.5&q=85&fm=jpg&crop=entropy&cs=srgb&ixid=eyJhcHBfaWQiOjE0NTg5fQ&s=838524a7e5b88ab7de5d54d0342b3d83" />
      
                <img class="image-8" src="https://images.unsplash.com/photo-1520720810040-f85066da6d93?ixlib=rb-0.3.5&q=85&fm=jpg&crop=entropy&cs=srgb&ixid=eyJhcHBfaWQiOjE0NTg5fQ&s=1b8b19ca158ac5b3bda2681ae833e5b6" />
        </div>
    </div>

  
</div>
              
            
!

CSS

              
                .random-container {
  width: 100%;
  height: 100%;
  position: relative;
  display: flex;
  justify-content: center;
}

.kun-gallery {
  flex: 1;
}

.kun-gallery ul {
  list-style-type: none;
  padding: 0;
}

.kun-gallery li {
  display: inline-block;
  padding: 0;
}

.kun-gallery ul li a {
  background-size: cover;
  background-position: center;
  width: 100%;
  height: 100%;
  display: block;
  cursor: pointer;
  transition: .2s ease-in-out;
}

.kun-gallery ul li a:hover {
  opacity: .9;
}
.kun-gallery ul li {
  position: relative;
  overflow: hidden;
  width: calc(25% - 3px);
  height: 25vw;
}

.kun-lightbox {
  z-index: 999999;
}

.gallery-container {
  width: 100%;
  height: 100%;
  display: block;
  content: "";
  position: fixed;
  z-index: 999998;
  top: 0;
  left: 0;
  display: none; /* changed to work on gallery */
}

.kun-modal {
  background: rgba(0, 0, 0, 0.8);
  width: 100%;
  height: 100%;
  position: fixed;
  top: 0;
  left: 0;
}

.gallery-container .left-arrow,
.gallery-container .right-arrow,
.gallery-container .close-icon {
  position: absolute;
  color: white;
  top: 50%;
  line-height: 0;
  left: 20px;
  font-size: 4vw;
  font-weight: 300;
  font-family: sans-serif;
  cursor: pointer;
  height: 50px;
  width: 50px;
  display: flex;
  justify-content: center;
  align-items: center;
}

.gallery-container .right-arrow {
  right: 20px;
  left: auto;
}

.gallery-container .close-icon {
  top: 20px;
  right: 20px;
  left: auto;
  font-size: 3vw;
}

.kun-lightbox img {
  max-width: 80%;
  max-height: 80%;
  height: auto;
  width: auto;
  margin: auto;
  position: fixed;
  display: none;
  left: 0;
  right: 0;
  bottom: 0;
  top: 0;
}
              
            
!

JS

              
                var time = 200;
var galleryBoxWidth = $(".kun-gallery li").width();

//$("body").append(".gallery-container");  <---- places lightbox above all else in DOM so nothing overlaps
$(".kun-gallery li").css("height", galleryBoxWidth);
$(".current-image").css("display", "inline");

/*------------------- gallery functionality ---------------------*/
$(".kun-gallery li a").click(function() {
  var imgClass = $(this).attr("class");
  
  $(".kun-lightbox img." + imgClass).addClass("current-image");
  $(".gallery-container").fadeIn(time);
  $(".kun-lightbox .current-image").fadeIn(time);
});

/*---------------- light box functionality ---------------------*/
$(".gallery-container .right-arrow").click(function() {
  var currentLightboxImage = $(".kun-lightbox img.current-image");
  var nextLightboxImage = currentLightboxImage.next("img");

  if (nextLightboxImage.length) {
    currentLightboxImage
      .fadeOut(time)
      .next(nextLightboxImage)
      .fadeIn(time)
      .toggleClass("current-image")
      .prev("img")
      .toggleClass("current-image");
  } else {
    currentLightboxImage.fadeOut(time).toggleClass("current-image");
    $(".kun-lightbox img:first")
      .fadeIn(time)
      .toggleClass("current-image");
  }
});

$(".gallery-container .left-arrow").click(function() {
  var currentLightboxImage = $(".kun-lightbox img.current-image");
  var nextLightboxImage = currentLightboxImage.prev("img");

  if (nextLightboxImage.length) {
    currentLightboxImage
      .fadeOut(time)
      .prev(nextLightboxImage)
      .fadeIn(time)
      .toggleClass("current-image")
      .next("img")
      .toggleClass("current-image");
  } else {
    currentLightboxImage.fadeOut(time).toggleClass("current-image");
    $(".kun-lightbox img:last")
      .fadeIn(time)
      .toggleClass("current-image");
  }
});

$(".kun-modal, .close-icon").click(function() {
  $(".gallery-container").fadeOut(time);
  $(".kun-lightbox img.current-image")
    .removeClass("current-image")
    .fadeOut(time);
});

              
            
!
999px

Console