為留言區加入圖片預覽
大約 1 分鐘...
有很多外掛可以實現燈箱效果,下面是這些外掛的範例:
LightGallery
在你的 HTML <head> 前寫入以下內容,其中 #waline-comment 是你的 Waline 留言框,需要根據實際情境進行替換。
<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
在你的 HTML <head> 前寫入以下內容,其中 #waline-comment 是你的 Waline 留言框,需要根據實際情境進行替換。
<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
在你的 HTML <head> 前寫入以下內容,其中 #waline-comment 是你的 Waline 留言框,需要根據實際情境進行替換。
<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: 評論區僅作評論展示,如有問題諮詢請去 Github Discussion 中提問。
