Posted in
10628
2:54 am, January 12, 2022
center image preview with lightbox and caption
I just wanted a thumbnail or preview of the image, where if clicked it would load into a lightbox, but the preview just shows the center of whatever image is added to it.
Note: I just picked random images and they are centered, so... /runs
HTML
<a href='https://i.imgur.com/2S7oKAT.png' class='fancybox'>
<div class='image-bg'></div>
<figcaption>Click This Image! (or dont...)</figcaption>
</a>
<!-- so now we can just switch the image source, but it needs a new bg class for each, which is annoying, unless we move to ... inline styles -->
<!-- It does make it a bit more messy, but easier to update inline. -->
<a href='https://images.pexels.com/photos/9589961/pexels-photo-9589961.jpeg?auto=compress&cs=tinysrgb&dpr=2&h=750&w=1260' class='fancybox'>
<div class='image-bg' style="background:url(https://images.pexels.com/photos/9589961/pexels-photo-9589961.jpeg?auto=compress&cs=tinysrgb&dpr=2&h=750&w=1260) center no-repeat;"></div>
<figcaption>Click This Image! (or dont...)</figcaption>
</a>
CSS
.image-bg {
height:200px;
width:100%;
margin-bottom:10px;
background:url(https://i.imgur.com/2S7oKAT.png) center no-repeat;
background-size:cover;
}
/* */
Scripts
<link rel="stylesheet" type="text/css" media="all" href="https://cdnjs.cloudflare.com/ajax/libs/fancybox/3.3.5/jquery.fancybox.css">
<script src="https://cdnjs.cloudflare.com/ajax/libs/fancybox/3.3.5/jquery.fancybox.js"></script>
Javascript
$(document).ready(function() {
$(".fancybox").fancybox({
helpers: {
title : {
type : 'float'
}
}
});
});
View Statistics
This Week
150
This Month
1083
This Year
3130
Add Comment
Other Items in images
Related Search Terms
Other Categories in Code
alpine js apps c css factorio font awesome images linux quick modals sqlite site bugs site updates slick slider sliders testing windows apps apache api apps asp bat bootstrap bootstrap templates charts cookies core css css filters css grid design elements docker domains emoji fancybox fonts foundation framework gimp git html icons ideas image formatting images javascript javascript functions jquery js linux mac misc modals mysql nginx node php php errors php function php functions php simple html dom pi400 python react regex sections simple_html_dom simplepie php site bugs site documentation slick slider sql sqlite ssh sublime svg svg css templates tools virtual box vscode vue webdev windows windows 11 windows commands wordpress