Posted in images
8570
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
143
This Month
711
This Year
1072

No Items Found.

Add Comment
Type in a Nick Name here
 
Search Code
Search Code by entering your search text above.
Welcome

This is my test area for webdev. I keep a collection of code here, mostly for my reference. Also if i find a good link, i usually add it here and then forget about it. more...

Subscribe to weekly updates about things i have added to the site or thought interesting during the last week.

You could also follow me on twitter or not... does anyone even use twitter anymore?

If you found something useful or like my work, you can buy me a coffee here. Mmm Coffee. ☕

❤️👩‍💻🎮

🪦 2000 - 16 Oct 2022 - Boots
Random Quote
When I realized that, no individual step is hard in any process. Building this airport I'm standing in right now started with a guy writing the architectural plans on paper. That's not hard for him to do. Then laying the first beam isn't had. The whole thing is really hard. So, just take each step kind of piece by piece and when I was able to do that and stop trying to chase this prize and started putting in the work, things just started coming together.
Unknown
Random CSS Property

scroll-margin-inline-start

The scroll-margin-inline-start property defines the margin of the scroll snap area at the start of the inline dimension that is used for snapping this box to the snapport. The scroll snap area is determined by taking the transformed border box, finding its rectangular bounding box (axis-aligned in the scroll container's coordinate space), then adding the specified outsets.
scroll-margin-inline-start css reference