admin管理员组文章数量:1291044
I'm trying to make a photo gallery page for all my photos in my post-gallery post and have a modal open when you click on the photos. In the page there will probably be almost 100 photos and i'm not sure how to do this in a good way without duplicating the code for the modal 100x. I have considered using plugins but i'd doing this as part of making my own website and learning developing wordpress themes so i'd prefer if the solution is done with code.
Something Best practice solution for this situation would be great!
I would appreciate tips in how to do this!
I'm trying to make a photo gallery page for all my photos in my post-gallery post and have a modal open when you click on the photos. In the page there will probably be almost 100 photos and i'm not sure how to do this in a good way without duplicating the code for the modal 100x. I have considered using plugins but i'd doing this as part of making my own website and learning developing wordpress themes so i'd prefer if the solution is done with code.
Something Best practice solution for this situation would be great!
I would appreciate tips in how to do this!
Share Improve this question edited Jun 3, 2021 at 15:12 fuxia♦ 107k38 gold badges255 silver badges459 bronze badges asked Jun 3, 2021 at 12:22 JomebJomeb 12 bronze badges 2 |2 Answers
Reset to default 0This W3Schools page shows how to create a lightbox with HTML, CSS and vanilla JS only: https://www.w3schools/howto/howto_js_lightbox.asp
If you have lots of photos on a page, you may want to remove the code related to the "thumbnail image controls" that they use in this example. But, other than that, I think their example shows what you want to do.
Another solution might be to use a jQuery-based library like Fancybox: http://fancyapps/fancybox/3/
i've found a solution for this using jquery. i set up an event that when you click on an image it opens a modal and gets the url of the image from the gallery and places it to the img tag in the modal. it works alright but it feels like a workaround atm
本文标签: Implementing a modal(lightbox) for all images in all postgallery posts
版权声明:本文标题:Implementing a modal(lightbox) for all images in all post-gallery posts 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1741512331a2382677.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
data
attribute to each image in the gallery likedata-img=""
and then for each image include it's ID or something else unique. Then when someone clicks on the image you grab the value of that attribute and use the unique identifier to tell the modal lightbox which image it should display. So to do this you have to be able to access/modify your 'gallery' output code. Then just include the modal script in your JS and you're all set. – Tony Djukic Commented Jun 4, 2021 at 13:41