Minimalist Image Lightbox With Smooth CSS Animations
File Size: | 3.25 KB |
---|---|
Views Total: | 3900 |
Last Update: | |
Publish Date: | |
Official Website: | Go to website |
License: | MIT |
![Minimalist Image Lightbox With Smooth CSS Animations](https://www.jqueryscript.net/images/image-viewer-smooth-animations.jpg)
A minimal image viewer jQuery script that enlarges and displays images in a fullscreen lightbox, with custom CSS3 powered open/close animations.
How to use it:
1. Create the HTML for the image viewer (lightbox).
<div id="image-viewer"> <span class="close">×</span> <img class="modal-content" id="full-image"> </div>
2. The main JavaScript (jQuery script) to trigger the image lightbox when clicking on the image within your page.
<div class="images"> <img src="1.jpg" alt="My Image" width="400" height="300" /> </div>
<script src="/path/to/cdn/jquery.slim.min.js"></script>
$(".images img").click(function(){ $("#full-image").attr("src", $(this).attr("src")); $('#image-viewer').show(); }); $("#image-viewer .close").click(function(){ $('#image-viewer').hide(); });
3. Style the image uses as the lightbox trigger.
img { border-radius: 5px; cursor: pointer; transition: 0.3s; } img:hover { opacity: 0.7; }
4. The main CSS styles & animations for the image lightbox.
#image-viewer { display: none; position: fixed; z-index: 1; padding-top: 100px; left: 0; top: 0; width: 100%; height: 100%; overflow: auto; background-color: rgb(0,0,0); background-color: rgba(0,0,0,0.9); } .modal-content { margin: auto; display: block; width: 80%; max-width: 700px; } .modal-content { animation-name: zoom; animation-duration: 0.6s; } @keyframes zoom { from {transform:scale(0)} to {transform:scale(1)} } #image-viewer .close { position: absolute; top: 15px; right: 35px; color: #f1f1f1; font-size: 40px; font-weight: bold; transition: 0.3s; } #image-viewer .close:hover, #image-viewer .close:focus { color: #bbb; text-decoration: none; cursor: pointer; } @media only screen and (max-width: 700px){ .modal-content { width: 100%; } }
This awesome jQuery plugin is developed by nasujon. For more Advanced Usages, please check the demo page or visit the official website.