Detail table: image popup

I have a detail table, with 2 image fields.
I would like to see enlarged images with a popup, like in lists.
Do you know any solutions?
Thanks

You can do this by modifying the instructions from this support doc article :point_right:

First, create a new row on your details page and add an HTML component. Inside the HTML component source code, add the following HTMLā€¦

<div id="myModal" class="modal"> <span class="close">&times;</span> <img id="myModalImg" class="modal-content" /></div>

Hereā€™s the part we need to modify. Because we canā€™t assign a custom class to the image field in a details component, we are going to use the default selector of img and replace all instances of list-image from the support doc article CSS and JS.

Add this CSS to your details pageā€¦

/* Style the Image Used to Trigger the Modal */
img {
  border-radius: 5px;
  cursor: pointer;
  transition: 0.3s;
}

img:hover {opacity: 0.7;}

/* The Modal (background) */
.modal {
  display: none; /* Hidden by default */
  position: fixed; /* Stay in place */
  z-index: 1000; /* Sit on top */
  padding-top: 100px; /* Location of the box */
  left: 0;
  top: 0;
  width: 100%; /* Full width */
  height: 100%; /* Full height */
  overflow: auto; /* Enable scroll if needed */
  background-color: rgb(0,0,0); /* Fallback color */
  background-color: rgba(0,0,0,0.9); /* Black w/ opacity */
}

/* Modal Content (Image) */
.modal-content {
  margin: auto;
  display: block;
  width: 80%;
  max-width: 700px;
}

/* Caption of Modal Image (Image Text) - Same Width as the Image */
#caption {
  margin: auto;
  display: block;
  width: 80%;
  max-width: 700px;
  text-align: center;
  color: #ccc;
  padding: 10px 0;
  height: 150px;
}

/* Add Animation - Zoom in the Modal */
.modal-content, #caption { 
  animation-name: zoom;
  animation-duration: 0.6s;
}

@keyframes zoom {
  from {transform:scale(0)} 
  to {transform:scale(1)}
}

/* The Close Button */
.close {
  position: absolute;
  top: 15px;
  right: 35px;
  color: #f1f1f1 !important;
  font-size: 40px;
  font-weight: bold;
  transition: 0.3s;
}

.close:hover,
.close:focus {
  color: #bbb;
  text-decoration: none;
  cursor: pointer;
}

/* 100% Image Width on Smaller Screens */
@media only screen and (max-width: 700px){
  .modal-content {
    width: 100%;
  }
}

And this JS to the details pageā€¦

$(function () {
  $('body').on('mousedown', function () {
    var modal = $("#myModal");
    $('img').on('click', function () {
      var modalImg = $('#myModalImg');
      modal.css('display', 'block');
      modalImg.attr('src', $(this).attr('src'));
    });
    $('.close').on('click', function () {
      modal.css('display', 'none');
    });
  });
});

Please keep in mind that because we are using the default selector of img, any element on your page with that selector will be able to opened in a modal popup.

https://dataflowstudios.tadabase.io/image-detail-popup#!/default/sample-data-table-details/5m9N0njzqk

@tim.young, thanks so much itā€™s great

1 Like

@tim.young This has really helped. However, I have come across an issue where I have a fixed Header Menu that seems to appear in front of the X to close the image. Is there anyway that I can get the Close button to appear in front of the header?

Can you try adding this CSS to your menu?

.your-menu-selector {
    z-index: 10;
}

@tim.young, I have probably stuck that in the wrong place as it didnā€™t seem to work (is it because I have the css to pin the menu to the top?

However, I did come up with another solution that seems to have done the trickā€¦ I just changed the position of the button in this part of the script which put it below the menu.

/* The Close Button */
.close {
position: absolute;
top: 55px;
right: 55px;
** col**or: #f1f1f1 !important;
font-size: 40px;
font-weight: bold;
transition: 0.3s;

Hi @tim.young! Thank you for this.

Iā€™m trying to do the same thing. This works but it is being navigated to a different page. How can I show the modal without it being routed to the image link?

I was able to prevent the navigation by adding ā€œreturn falseā€ to the event on javascript.

$(function () {
$(ā€˜bodyā€™).on(ā€˜mousedownā€™, function () {
var modal = $("#myModal");
$(ā€˜imgā€™).on(ā€˜clickā€™, function () {

  var modalImg = $('#myModalImg');
  modal.css('display', 'block');
  modalImg.attr('src', $(this).attr('src'));
   return false;
//   window.onbeforeunload = function() {
//   return "";
// }
});
 
  
$('.close').on('click', function () {
  modal.css('display', 'none');
});

});
});

Has there been any update here as far as enabling the image pop-up in the details (or profile) page ā€“ I havenā€™t spent too much time playing with it but one issue i ran into with this solution is if the page was being popped up as a modal, it breaks it- maybe ill just change some of the class names