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

              
                <style>
  
  			/*!
			 * @see {@link https://cdnjs.cloudflare.com/ajax/libs/github-fork-ribbon-css/0.2.2/gh-fork-ribbon.css}
			 */
			.github-fork-ribbon{width:12.1em;height:12.1em;position:absolute;overflow:hidden;top:0;right:0;z-index:9999;pointer-events:none;font-size:13px;text-decoration:none;text-indent:-999999px;}.github-fork-ribbon.fixed{position:fixed;}.github-fork-ribbon:before,.github-fork-ribbon:after{position:absolute;display:block;width:15.38em;height:1.54em;top:3.23em;right:-3.23em;-webkit-box-sizing:content-box;box-sizing:content-box;-webkit-transform:rotate(45deg);-ms-transform:rotate(45deg);transform:rotate(45deg);}.github-fork-ribbon:before{content:"";padding:.38em 0;background-color:#a00;background-image:-webkit-gradient(linear,left top,left bottom,from(rgba(0,0,0,0)),to(rgba(0,0,0,0.15)));background-image:-webkit-linear-gradient(top,rgba(0,0,0,0),rgba(0,0,0,0.15));background-image:-o-linear-gradient(top,rgba(0,0,0,0),rgba(0,0,0,0.15));background-image:linear-gradient(to bottom,rgba(0,0,0,0),rgba(0,0,0,0.15));-webkit-box-shadow:0 .15em .23em 0 rgba(0,0,0,0.5);box-shadow:0 .15em .23em 0 rgba(0,0,0,0.5);pointer-events:auto;}.github-fork-ribbon:after{content:attr(data-ribbon);color:#fff;font:700 1em "Helvetica Neue",Helvetica,Arial,sans-serif;line-height:1.54em;text-decoration:none;text-shadow:0 -.08em rgba(0,0,0,0.5);text-align:center;text-indent:0;padding:.15em 0;margin:.15em 0;border-width:.08em 0;border-style:dotted;border-color:#fff;border-color:rgba(255,255,255,0.7);}.github-fork-ribbon.left-top,.github-fork-ribbon.left-bottom{right:auto;left:0;}.github-fork-ribbon.left-bottom,.github-fork-ribbon.right-bottom{top:auto;bottom:0;}.github-fork-ribbon.left-top:before,.github-fork-ribbon.left-top:after,.github-fork-ribbon.left-bottom:before,.github-fork-ribbon.left-bottom:after{right:auto;left:-3.23em;}.github-fork-ribbon.left-bottom:before,.github-fork-ribbon.left-bottom:after,.github-fork-ribbon.right-bottom:before,.github-fork-ribbon.right-bottom:after{top:auto;bottom:3.23em;}.github-fork-ribbon.left-top:before,.github-fork-ribbon.left-top:after,.github-fork-ribbon.right-bottom:before,.github-fork-ribbon.right-bottom:after{-webkit-transform:rotate(-45deg);-ms-transform:rotate(-45deg);transform:rotate(-45deg);}
		</style>
</head>
<body>
  
  <h1 class="title">img-lightbox Demo</h1>
	<p>Responsive no-jQuery pure JS/CSS Lightbox for images, no dependencies, 10kb unminified source code, with demo</p>
	<h2>Features</h2>
	<ul>
		<li>Simple initialization</li>
		<li>SPA / PWA friendly: prevents multiple same events assigning</li>
		<li>Debounced launch, default 500ms, custom rate can be set with rate property of options object</li>
		<li>Preloading spinner that is unset after onload event succeeds</li>
		<li>Pure CSS Retina Ready UI images, no external ones (prompted by github.com/jasomdotnet, thanks)</li>
		<li>Custom event callbacks</li>
	</ul>
	<h2>CDN</h2>
	<h4>jsDelivr</h4>
	<p>
		<code>https://cdn.jsdelivr.net/gh/englishextra/img-lightbox@latest/img-lightbox.min.js</code>
		<br />
		<code>https://cdn.jsdelivr.net/gh/englishextra/img-lightbox@latest/img-lightbox.min.css</code>
	</p>
	<h4>unpkg</h4>
	<p>
		<code>https://unpkg.com/img-lightbox@latest/img-lightbox.js</code>
		<br />
		<code>https://unpkg.com/img-lightbox@latest/img-lightbox.css</code>
	</p>
	<h2>Install</h2>
	<h4>npm</h4>
	<p>
		<code>npm install img-lightbox</code>
	</p>
	<h4>bower</h4>
	<p>
		<code>bower install img-lightbox</code>
	</p>
	<h2>Setup</h2>
	<p><code>class</code> is not required. They are used here to select elements. You may use some other method for elements selection.</p>
	<p><code>data-src</code> is deprecated, but supported for compatibility.</p>
	<p><code>href</code> is required, and contains URL of your image.</p>
	<h2><a href="https://farm1.staticflickr.com/955/27854475488_5f82a379ca_z.jpg" class="img-lightbox-link" aria-hidden="true" rel="lightbox"><img src="https://farm1.staticflickr.com/955/27854475488_5f82a379ca_z.jpg" alt="Image Lightbox" /></a></h2>
	<pre><code>&lt;a href=&quot;https://farm1.staticflickr.com/955/27854475488_5f82a379ca_z.jpg&quot;
class=&quot;img-lightbox-link&quot;
aria-hidden=&quot;true&quot;
rel=&quot;lightbox&quot;&gt;&lt;img src=&quot;https://farm1.staticflickr.com/955/27854475488_5f82a379ca_z.jpg&quot; alt=&quot;Image Lightbox&quot; /&gt;&lt;/a&gt;</code></pre>
	<h2>Initialize</h2>
	<pre><code>imgLightbox(&quot;img-lightbox-link&quot;);</code></pre>
	<h2>Tips</h2>
	<p>SPA / PWA developers don't need to bother: built-in class is added to a link.</p>
	<p>That way you avoid multiple assignments to a single element.</p>
	<h2>Examples of event handling</h2>
	<pre><code>(function(root){
	&quot;use strict&quot;;
	if (root.imgLightbox) {
		imgLightbox(&quot;img-lightbox-link&quot;, {
			onCreated: function () {
				/* show your preloader */
			},
			onLoaded: function () {
				/* hide your preloader */
			},
			onError: function () {
				/* hide your preloader */
			},
			onClosed: function () {
				/* hide your preloader */
			},
			rate: 500 /* default: 500 */
		});
	}
})(&quot;undefined&quot; !== typeof window ? window : this);</code></pre>
	<h2>GitHub</h2>
	<p><a href="https://github.com/englishextra/img-lightbox">englishextra/img-lightbox</a></p>
	<h2>License</h2>
	<p>Available under <a href="https://opensource.org/licenses/MIT">MIT License</a></p>
  
  <a class="github-fork-ribbon right-top" href="https://github.com/englishextra/img-lightbox" target="_blank" rel="noopener noreferrer" title="Fork me on GitHub" data-ribbon="Fork me on GitHub">Fork me on GitHub</a>
		
              
            
!

CSS

              
                /*!
 * some animations from animate.css
 * @see {@link https://github.com/daneden/animate.css}
 * daneden.github.io/animate.css/
 */
/* .animated {
	animation-duration: 2s;
	animation-fill-mode: both;
} */
@-webkit-keyframes fadeIn {
	0% {
		opacity: 0;
	}
	100% {
		opacity: 1;
	}
}
@keyframes fadeIn {
	0% {
		opacity: 0;
	}
	100% {
		opacity: 1;
	}
}

.fadeIn {
	-webkit-animation-name: fadeIn;
	animation-name: fadeIn;
}

@-webkit-keyframes fadeInUp {
	0% {
		opacity: 0;
		-webkit-transform: translate3d(0, 100%, 0);
		transform: translate3d(0, 100%, 0);
	}
	100% {
		opacity: 1;
		-webkit-transform: none;
		transform: none;
	}
}

@keyframes fadeInUp {
	0% {
		opacity: 0;
		-webkit-transform: translate3d(0, 100%, 0);
		transform: translate3d(0, 100%, 0);
	}
	100% {
		opacity: 1;
		-webkit-transform: none;
		transform: none;
	}
}

.fadeInUp {
	-webkit-animation-name: fadeInUp;
	animation-name: fadeInUp;
}

@-webkit-keyframes fadeOut {
	0% {
		opacity: 1;
	}
	100% {
		opacity: 0;
	}
}

@keyframes fadeOut {
	0% {
		opacity: 1;
	}
	100% {
		opacity: 0;
	}
}

.fadeOut {
	-webkit-animation-name: fadeOut;
	animation-name: fadeOut;
}

@-webkit-keyframes fadeOutDown {
	0% {
		opacity: 1;
	}
	100% {
		opacity: 0;
		-webkit-transform: translate3d(0, 100%, 0);
		transform: translate3d(0, 100%, 0);
	}
}

@keyframes fadeOutDown {
	0% {
		opacity: 1;
	}
	100% {
		opacity: 0;
		-webkit-transform: translate3d(0, 100%, 0);
		transform: translate3d(0, 100%, 0);
	}
}

.fadeOutDown {
	-webkit-animation-name: fadeOutDown;
	animation-name: fadeOutDown;
}

/*!
 * img lightbox
 */
.img-lightbox {
	display: none;
	opacity: 0;
	width: 100%;
	height: 100%;
	position: fixed;
	top: 0;
	left: 0;
	background-color: rgba(0, 0, 0, 0.92);
	z-index: 999999;
}

.img-lightbox img {
	display: block;
	opacity: 0;
	max-width: 90%;
	max-height: 90%;
	position: absolute;
	top: 0;
	bottom: 0;
	left: 0;
	right: 0;
	background-color: transparent;
	border: 0;
	-webkit-box-shadow: 0.267rem 0.267rem 0.267rem 0 rgba(3, 3, 3, 0.3);
	box-shadow: 0.267rem 0.267rem 0.267rem 0 rgba(3, 3, 3, 0.3);
	vertical-align: middle;
	-webkit-user-select: none;
	-moz-user-select: none;
	-ms-user-select: none;
	user-select: none;
	cursor: -webkit-zoom-out;
	cursor: zoom-out;
	margin: auto;
}

/*!
 * reset for animate.css
 * daneden.github.io/animate.css/
 */
.img-lightbox.animated,
.img-lightbox img.animated {
	-webkit-animation-duration: 0.4s;
	animation-duration: 0.4s;
	-webkit-animation-fill-mode: both;
	animation-fill-mode: both;
}

/*!
 * another pure css spinner
 * @see {@link https://epic-spinners.epicmax.co/}
 */
.img-lightbox .half-circle-spinner,
.img-lightbox .half-circle-spinner * {
	-webkit-box-sizing: border-box;
	box-sizing: border-box;
}

.img-lightbox .half-circle-spinner {
	width: 60px;
	height: 60px;
	border-radius: 100%;
	position: relative;
	margin: 0;
	position: fixed;
	top: 50%;
	left: 50%;
	margin-right: -50%;
	-webkit-transform: translate(-50%, -50%);
	transform: translate(-50%, -50%);
}

.img-lightbox .half-circle-spinner .circle {
	content: "";
	position: absolute;
	width: 100%;
	height: 100%;
	border-radius: 100%;
	border: calc(60px / 10) solid transparent;
}

.img-lightbox .half-circle-spinner .circle.circle-1 {
	border-top-color: #ffffff;
	-webkit-animation: half-circle-spinner-animation 1s infinite;
	animation: half-circle-spinner-animation 1s infinite;
}

.img-lightbox .half-circle-spinner .circle.circle-2 {
	border-bottom-color: #ffffff;
	-webkit-animation: half-circle-spinner-animation 1s infinite alternate;
	animation: half-circle-spinner-animation 1s infinite alternate;
}

@-webkit-keyframes half-circle-spinner-animation {
	0% {
		-webkit-transform: rotate(0deg);
		transform: rotate(0deg);
	}
	100% {
		-webkit-transform: rotate(360deg);
		transform: rotate(360deg);
	}
}

@keyframes half-circle-spinner-animation {
	0% {
		-webkit-transform: rotate(0deg);
		transform: rotate(0deg);
	}
	100% {
		-webkit-transform: rotate(360deg);
		transform: rotate(360deg);
	}
}

.img-lightbox.is-loaded .half-circle-spinner {
	display: none;
}

.img-lightbox .btn-close {
	position: fixed;
	top: 1.000rem;
	right: 1.000rem;
	width: 1.500rem;
	height: 1.500rem;
}

/*!
 * pure css version
 * @see {@link https://codepen.io/brissmyr/pen/egidw}
 */
.img-lightbox .btn-close:before,
.img-lightbox .btn-close:after {
	content: " ";
	width: 0.125em;
	height: 1.5em;
	position: absolute;
	right: 0.625em;
	background-color: #ffffff;
}

.img-lightbox .btn-close:before {
	-webkit-transform: rotate(45deg);
	transform: rotate(45deg);
}

.img-lightbox .btn-close:after {
	-webkit-transform: rotate(-45deg);
	transform: rotate(-45deg);
}

/*!
 * @see {@link https://github.com/englishextra/iframe-lightbox/issues/12}
 */
.img-lightbox--open {
	overflow: hidden;
	-webkit-overflow-scrolling: touch;
	-ms-touch-action: auto;
	touch-action: auto;
	height: auto;
}

              
            
!

JS

              
                /*!
 * @see {@link https://github.com/englishextra/img-lightbox}
 * imgLightbox
 * requires this very img-lightbox.js, and animate.css, img-lightbox.css
 * @params {String} linkClass
 * @params {Object} settings object
 * imgLightbox(linkClass, settings)
 * passes jshint
 */
/*jshint -W014 */
(function (root, document) {
	"use strict";
	var docElem = document.documentElement || "";
	var docBody = document.body || "";
	var animatedClass = "animated";
	var appendChild = "appendChild";
	var classList = "classList";
	var createElement = "createElement";
	var getAttribute = "getAttribute";
	var getElementsByClassName = "getElementsByClassName";
	var getElementsByTagName = "getElementsByTagName";
	var innerHTML = "innerHTML";
	var style = "style";
	var _addEventListener = "addEventListener";
	var _length = "length";
	var btnCloseClass = "btn-close";
	var containerClass = "img-lightbox";
	var fadeInClass = "fadeIn";
	var fadeInUpClass = "fadeInUp";
	var fadeOutClass = "fadeOut";
	var fadeOutDownClass = "fadeOutDown";
	var imgLightboxOpenClass = "img-lightbox--open";
	var imgLightboxLinkIsBindedClass = "img-lightbox-link--is-binded";
	var isLoadedClass = "is-loaded";
	var dummySrc = "data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAQAAAC1HAwCAAAAC0lEQVR42mNkYAAAAAYAAjCB0C8AAAAASUVORK5CYII=";
	var isMobile = navigator.userAgent.match(/(iPad)|(iPhone)|(iPod)|(Android)|(PlayBook)|(BB10)|(BlackBerry)|(Opera Mini)|(IEMobile)|(webOS)|(MeeGo)/i);
	var isTouch = isMobile !== null || document.createTouch !== undefined || "ontouchstart" in root || "onmsgesturechange" in root || navigator.msMaxTouchPoints;
	var debounce = function (func, wait) {
		var timeout;
		var args;
		var context;
		var timestamp;
		return function () {
			context = this;
			args = [].slice.call(arguments, 0);
			timestamp = new Date();
			var later = function () {
				var last = new Date() - timestamp;
				if (last < wait) {
					timeout = setTimeout(later, wait - last);
				} else {
					timeout = null;
					func.apply(context, args);
				}
			};
			if (!timeout) {
				timeout = setTimeout(later, wait);
			}
		};
	};
	var callCallback = function (func, data) {
		if (typeof func !== "function") {
			return;
		}
		var caller = func.bind(this);
		caller(data);
	};
	var hideImgLightbox = function (callback) {
		var container = document[getElementsByClassName](containerClass)[0] || "";
		var img = container ? container[getElementsByTagName]("img")[0] || "" : "";
		var hideContainer = function () {
			container[classList].remove(fadeInClass);
			container[classList].add(fadeOutClass);
			var hideImg = function () {
				container[classList].remove(animatedClass);
				container[classList].remove(fadeOutClass);
				img[classList].remove(animatedClass);
				img[classList].remove(fadeOutDownClass);
				img.onload = function () {
					container[classList].remove(isLoadedClass);
				};
				img.src = dummySrc;
				container[style].display = "none";
				callCallback(callback, root);
			};
			var timer = setTimeout(function () {
					clearTimeout(timer);
					timer = null;
					hideImg();
				}, 400);
		};
		if (container && img) {
			img[classList].remove(fadeInUpClass);
			img[classList].add(fadeOutDownClass);
			var timer = setTimeout(function () {
					clearTimeout(timer);
					timer = null;
					hideContainer();
				}, 400);
		}
		docElem[classList].remove(imgLightboxOpenClass);
		docBody[classList].remove(imgLightboxOpenClass);
	};
	var imgLightbox = function (linkClass, settings) {
		var _linkClass = linkClass || "";
		var options = settings || {};
		var rate = options.rate || 500;
		var touch = options.touch;
		var onError = options.onError;
		var onLoaded = options.onLoaded;
		var onCreated = options.onCreated;
		var onClosed = options.onClosed;
		var link = document[getElementsByClassName](_linkClass) || "";
		var container = document[getElementsByClassName](containerClass)[0] || "";
		var img = container ? container[getElementsByTagName]("img")[0] || "" : "";
		if (!container) {
			container = document[createElement]("div");
			container[classList].add(containerClass);
			var html = [];
			html.push('<img src="' + dummySrc + '" alt="" />');
			html.push('<div class="half-circle-spinner"><div class="circle circle-1"></div><div class="circle circle-2"></div></div>');
			html.push('<a href="javascript:void(0);" class="btn-close"></a>');
			container[innerHTML] = html.join("");
			docBody[appendChild](container);
			img = container ? container[getElementsByTagName]("img")[0] || "" : "";
			var btnClose = container ? container[getElementsByClassName](btnCloseClass)[0] || "" : "";
			var handleImgLightboxContainer = function () {
				hideImgLightbox(onClosed);
			};
			container[_addEventListener]("click", handleImgLightboxContainer);
			btnClose[_addEventListener]("click", handleImgLightboxContainer);
			root[_addEventListener]("keyup", function (ev) {
				if (27 === (ev.which || ev.keyCode)) {
					hideImgLightbox(onClosed);
				}
			});
		}
		var arrange = function (e) {
			var hrefString = e[getAttribute]("href") || e[getAttribute]("data-src") || "";
			var dataTouch = e[getAttribute]("data-touch") || "";
			if (!hrefString) {
				return;
			}
			var handleImgLightboxLink = function (ev) {
				ev.stopPropagation();
				ev.preventDefault();
				docElem[classList].add(imgLightboxOpenClass);
				docBody[classList].add(imgLightboxOpenClass);
				container[classList].remove(isLoadedClass);
				var logic = function logic() {
					if (onCreated) {
						callCallback(onCreated, root);
					}
					container[classList].add(animatedClass);
					container[classList].add(fadeInClass);
					img[classList].add(animatedClass);
					img[classList].add(fadeInUpClass);
					img.onload = function () {
						container[classList].add(isLoadedClass);
						if (onLoaded) {
							callCallback(onLoaded, root);
						}
					};
					img.onerror = function () {
						if (onError) {
							callCallback(onError, root);
						}
					};
					img.src = hrefString;
					container[style].display = "block";
				};
				debounce(logic, rate).call();
			};
			if (!e[classList].contains(imgLightboxLinkIsBindedClass)) {
				e[classList].add(imgLightboxLinkIsBindedClass);
				e[_addEventListener]("click", handleImgLightboxLink);
				if (isTouch && (touch || dataTouch)) {
					e[_addEventListener]("touchstart", handleImgLightboxLink);
				}
			}
		};
		if (container && img && link) {
			var i,
			l;
			for (i = 0, l = link[_length]; i < l; i += 1) {
				arrange(link[i]);
			}
			i = l = null;
		}
	};
	root.imgLightbox = imgLightbox;
})("undefined" !== typeof window ? window : this, document);




	(function(root) {
		"use strict";
		if (root.imgLightbox) {
			imgLightbox("img-lightbox-link", {
				onCreated: function() {
					/* show your preloader */
				},
				onLoaded: function() {
					/* hide your preloader */
				},
				onError: function() {
					/* hide your preloader */
				},
				onClosed: function() {
					/* hide your preloader */
				},
				rate: 500 /* default: 500 */
			});
		}
	})("undefined" !== typeof window ? window : this);

              
            
!
999px

Console