Jump to content

Show a modal / lightbox with only text when user clicks on an image

Go to solution Solved by GabeSimon,

Recommended Posts

Hello,

I have a section of our website with our team and each of their headshots. When a visitor clicks on each image, I'd like it to show that team member's bio in a modal/lightbox. Any recommendations for this functionality? 

A couple of examples of how this implemented in non-square space sites

1. https://www.limbix.com/about. If you click on any of the images, a modal comes up with the bio

2. https://equip.health/aboutus/. If you hover over on any of the team member images, it shows their full bio

3. https://www.treatmyocd.com/.  Go to the "Meet the NOCD Therapy team". If you click "read bio" on any of the cards, if shows the bio. 

 

Note: That when you click the image, I want it to only show text, and not the image with a caption. 

Thank you in advance! 

 

Edited by GabeSimon
Link to comment
  • Solution

I figured it out with a little help from ChatGPT-4!

Here's how to do it. 

Add the following as page header code injection

<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.6.1/jquery.min.js"></script>
 <script>
    $(document).ready(function() {
      $('.clickable-element').click(function() {
        var bioText = $(this).data('bio');
        $('.bio-content p').text(bioText);
        $('#lightbox-overlay').fadeIn();
      });

      $('#lightbox-overlay').click(function() {
        $(this).fadeOut();
      });

      $('.bio-content').click(function(event) {
        event.stopPropagation();
      });
    });
  </script>
 <style>
    #lightbox-overlay {
      display: none;
      position: fixed;
      top: 0;
      left: 0;
      width: 100%;
      height: 100%;
      background-color: rgba(0, 0, 0, 0.8);
      z-index: 9999999;
    }

    #biography {
      position: relative;
      display: flex;
      justify-content: center;
      align-items: center;
      width: 100%;
      height: 100%;
            z-index: 9999999;
      opacity: 1;
    }

    .bio-content {
      background-color: #F7F0E5;
      padding: 20px;
      border-radius: 5px;
      max-width: 500px;
      text-align: left;
      color: #880808;
      opacity: 1;
      z-index: 9999999;

    }
   
   .clickable-element img{
     border-radius: 40px;
     width:100%;
   }
   
   .clickable-element:hover {
      cursor: pointer;
    }
   
  </style>

<div id="lightbox-overlay">
    <div id="biography">
      <div class="bio-content">
        <p></p>
      </div>
    </div>
  </div>

Then on the page, create code blocks for each team member image. In that, put the following: 

<div class="clickable-element" data-bio="Jean shorts tbh mlkshk, migas XOXO shabby chic knausgaard post-ironic marfa messenger bag craft beer adaptogen. XOXO tilde lumbersexual plaid unicorn pug, yr try-hard.">
    <img src="your image url" alt="Image description 1" />
  </div>

 And that does it!  You can edit the CSS to fit your preferred formatting of course. 

Link to comment
  • 6 months later...

Hello! 

I'm trying to do something similar for bios - used this code and it worked great!! 

However, the mobile view got a little messed up with the overflow text. And there seems to be no way of clicking out of the bio content back to where the images are. 

Is there a way to fix this? Thank you!!! 

Link to comment
On 10/27/2023 at 1:37 PM, theproper said:

Hello! 

I'm trying to do something similar for bios - used this code and it worked great!! 

However, the mobile view got a little messed up with the overflow text. And there seems to be no way of clicking out of the bio content back to where the images are. 

Is there a way to fix this? Thank you!!! 

Can you share link to page where you use lightbox? We can take a look

Email me if you have need any help (free, of course.). Answer within 24 hours. 
Or send to forum message

Contact Customer Care - Learn CSS - Buy me a coffee (thank you!)

Link to comment

Create an account or sign in to comment

You need to be a member in order to leave a comment

×
×
  • Create New...

Squarespace Webinars

Free online sessions where you’ll learn the basics and refine your Squarespace skills.

Hire a Designer

Stand out online with the help of an experienced designer or developer.