LATEST >>

Welcome Here And Thanks For Visiting. Like Us On Facebook...

EXEIdeas – Let's Your Mind Rock » HTML-CSS-PHP-JavaScript / JavaScript Codes » Pure Vanilla JavaScript Image Lightbox With Custom Controls

Pure Vanilla JavaScript Image Lightbox With Custom Controls

Pure-Vanilla-JavaScript-Image-Lightbox-With-Custom-Controls
A simple, lightweight (10kb unminified), and mobile-friendly pure JavaScript lightbox to show images in a popup box with a close button. This vanilla JavaScript lightbox plugin doesn’t require any external framework or library to work.

  • Easy to initialize.
  • Responsive, fully mobile friendly.
  • Debounced launch, default 500ms, the customs rate can be set with rate property of options object.
  • A preloading spinner that is unset after onload event succeeds.
  • Pure CSS Retina Ready UI images.
  • Custom event callback functions.

There are many code snippets available online or on many other blogs and websites, but everyone cannot optimize your blog or website, so you need some optimized code snippets. So now checkout out the code snippet for your blog and website that will give you all features for your desired code. Now grab the ready-to-use code and paste it where you want.

Features:

  1. Light Weight.
  2. Pure JavaScript.
  3. Cross Browser.
  4. No JQuery Files.
  5. Fully Customizable.
  6. Responsive.

How To Add Drag And Drop Reorder List & DIV Using Pure JavaScript?

There are a few easy and understandable steps to achieve your desired functionality that we are gonna share below. Follow each step perfectly.

Recommended For You:
15 Stylish And Attractive Custom CSS For Scroll Bar Using CSS3

CSS:

<style type="text/css">
@-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{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:.267rem .267rem .267rem 0 rgba(3,3,3,0.3);box-shadow:.267rem .267rem .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}
.img-lightbox.animated,.img-lightbox img.animated{-webkit-animation-duration:.4s;animation-duration:.4s;-webkit-animation-fill-mode:both;animation-fill-mode:both}
.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:#fff;-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:#fff;-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:1rem;right:1rem;width:1.5rem;height:1.5rem}
.img-lightbox .btn-close:before,.img-lightbox .btn-close:after{content:" ";width:.125em;height:1.5em;position:absolute;right:.625em;background-color:#fff}
.img-lightbox .btn-close:before{-webkit-transform:rotate(45deg);transform:rotate(45deg)}
.img-lightbox .btn-close:after{-webkit-transform:rotate(-45deg);transform:rotate(-45deg)}
.img-lightbox--open{overflow:hidden;-webkit-overflow-scrolling:touch;-ms-touch-action:auto;touch-action:auto;height:auto}
</style>
.

HTML:

<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>

JavaScript:

<script type="text/javascript">
(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 */ ,
touch: false /* default: false - use with care for responsive images in links on vertical mobile screens */
});
}
})("undefined" !== typeof window ? window : this);
</script>
<script type="text/javascript">
!function(a,b){"use strict";var c=b.documentElement||"",d=b.body||"",e="animated",f="btn-close",g="img-lightbox",h="fadeIn",i="fadeInUp",j="fadeOut",k="fadeOutDown",l="img-lightbox-window--is-binded",m="img-lightbox--open",n="img-lightbox-link--is-binded",o="is-loaded",p="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAQAAAC1HAwCAAAAC0lEQVR42mNkYAAAAAYAAjCB0C8AAAAASUVORK5CYII=",q=navigator.userAgent.match(/(iPad)|(iPhone)|(iPod)|(Android)|(PlayBook)|(BB10)|(BlackBerry)|(Opera Mini)|(IEMobile)|(webOS)|(MeeGo)/i),r=null!==q||void 0!==b.createTouch||"ontouchstart"in a||"onmsgesturechange"in a||navigator.msMaxTouchPoints,s=function(a,b){var c,d,e,f;return function(){e=this,d=[].slice.call(arguments,0),f=new Date;var g=function h(){var g=new Date-f;g<b?c=setTimeout(h,b-g):(c=null,a.apply(e,d))};c||(c=setTimeout(g,b))}},t=function(a,b){if("function"===typeof a){var c=a.bind(this);c(b)}},u=function(a){a&&(a.style.display="block")},v=function(a){a&&(a.style.display="none")},w=function(f){var l=b.getElementsByClassName(g)[0]||"",n=l?l.getElementsByTagName("img")[0]||"":"",q=function(){l.classList.remove(h),l.classList.add(j);var b=function(){l.classList.remove(e),l.classList.remove(j),n.classList.remove(e),n.classList.remove(k),n.onload=function(){l.classList.remove(o)},n.src=p,v(l),t(f,a)},c=setTimeout(function(){clearTimeout(c),c=null,b()},400)};if(l&&n){n.classList.remove(i),n.classList.add(k);var r=setTimeout(function(){clearTimeout(r),r=null,q()},400)}c.classList.remove(m),d.classList.remove(m)},x=function(j,k){var q=j||"",v=k||{},x=v.rate||500,y=v.touch,z=v.onError,A=v.onLoaded,B=v.onCreated,C=v.onClosed,D=b.getElementsByClassName(q)||"",E=b.getElementsByClassName(g)[0]||"",F=E?E.getElementsByTagName("img")[0]||"":"";if(!E){E=b.createElement("div"),E.classList.add(g);var G=[];G.push('<img src="'+p+'" alt="" />'),G.push('<div class="half-circle-spinner"><div class="circle circle-1"></div><div class="circle circle-2"></div></div>'),G.push('<a href="javascript:void(0);" class="btn-close"></a>'),E.innerHTML=G.join(""),d.appendChild(E),F=E?E.getElementsByTagName("img")[0]||"":"";var H=E?E.getElementsByClassName(f)[0]||"":"",I=function(){w(C)};E.addEventListener("click",I),H.addEventListener("click",I),c.classList.contains(l)||(c.classList.add(l),a.addEventListener("keyup",function(a){27===(a.which||a.keyCode)&&w(C)}))}var J=function(b){var f=b.getAttribute("href")||b.getAttribute("data-src")||"",g=b.getAttribute("data-touch")||"";if(f){var j=function(b){b.stopPropagation(),b.preventDefault(),c.classList.add(m),d.classList.add(m),E.classList.remove(o);var g=function(){B&&t(B,a),E.classList.add(e),E.classList.add(h),F.classList.add(e),F.classList.add(i),F.onload=function(){E.classList.add(o),A&&t(A,a)},F.onerror=function(){z&&t(z,a)},F.src=f,u(E)};s(g,x).call()};b.classList.contains(n)||(b.classList.add(n),b.addEventListener("click",j),r&&(y||g)&&b.addEventListener("touchstart",j))}};if(E&&F&&D){var K,L;for(K=0,L=D.length;K<L;K+=1)J(D[K]);K=L=null}};a.imgLightbox=x}("undefined"!==typeof window?window:this,document); 
</script>

Customization:

No need to customize it. Just copy-paste. Rest edit the code as per comments and need.

Troubleshooting the Errors:

Do it with concentration and patience. Check your all steps again and all codes or scripts. If you find any error you can contact us anytime via comment or better via email, We are always here to help you.

Recommended For You:
Awesome And Stylish Big Full Page Author Box For Web Pages

Final Words:

That’s all we have. We hope that you liked this article. If you have any problem with this code in your template then feel free to contact us with a full explanation of your problem. We will reply to you as time allows us If you have any doubts or problems please comment below. We are happy to help you! If you liked this article, Don’t forget to share this with your friends so they can also take benefit from it and leave.

You Like It, Please Share This Recipe With Your Friends Using...

Be the first to write a comment.

Leave a Reply

Your email address will not be published. Required fields are marked *