Image Preview for Comment List

About 1 min...

There are many plugins that can achieve the lightbox effect, here are some examples of these plugins:

LightGallery

Write the following content before your HTML <head>, where #waline-comment is your Waline comment box, which needs to be replaced according to the actual scene.

<link
  rel="stylesheet"
  href="https://unpkg.com/lightgallery@v2/css/lightgallery-bundle.css"
/>
<srciprt src="https://unpkg.com/lightgallery@v2/lightgallery.umd.min.js" />
<script>
  document.addEventListener('click', (e) => {
    const images = [].slice
      .call(document.querySelectorAll('#waline-comment .vcontent img'))
      .filter((img) => img.width > 20);

    if (images.indexOf(e.target) === -1) {
      return;
    }
    if (!e.target.gallery) {
      e.target.gallery = window.lightGallery(e.target.parentNode);
    }
    e.target.gallery.openGallery(0);
  });
</script>

Lightbox2

Write the following content before your HTML <head>, where #waline-comment is your Waline comment box, which needs to be replaced according to the actual scene.

<link
  rel="stylesheet"
  href="https://unpkg.com/lightbox2@v2/dist/css/lightbox.min.css"
/>
<script src="https://unpkg.com/lightbox2@v2/dist/js/lightbox-plus-jquery.min.js"></script>
<script>
  document.addEventListener('click', (e) => {
    const lightbox = new Lightbox();
    const images = [].slice
      .call(document.querySelectorAll('#waline-comment .vcontent img'))
      .filter((img) => img.width > 20);

    if (images.indexOf(e.target) === -1) {
      return;
    }

    const $link = $('<a />', {
      href: e.target.src,
      'data-title': e.target.alt,
      rel: 'lightbox',
    });
    lightbox.start($link);
  });
</script>

Fancybox

Write the following content before your HTML <head>, where #waline-comment is your Waline comment box, which needs to be replaced according to the actual scene.

<script src="https://unpkg.com/@fancyapps/ui/dist/fancybox.umd.js"></script>
<link
  rel="stylesheet"
  href="https://unpkg.com/@fancyapps/ui/dist/fancybox.css"
/>
<script>
  Fancybox.bind('#waline-comment .vcontent img');
</script>
TIPS: The comment area is only for demo. If you have any questions, please go to Github Discussion to ask.
What do you think?
  • 0
  • 0
  • 0
  • 0
  • 0
  • 0
Comments
  • Latest
  • Oldest
  • Hottest
Powered by Waline v2.14.7