JQuery gallery with multiple instances not working

1 day ago 2
ARTICLE AD BOX

I have a webpage where I want to get multiple instances of the same JQuery-powered gallery tool.

The first instance works just fine; all the individul items are clickable, the arrows work, and moving through thumbnails also works.

Second instance starts showing problems - when you click on any item it takes you a random one (within the same gallery, NOT mixing up with the other instances). Thumbnails and arrows still work.

From third instance on - clicking on any item just brings up "loading" but nothing shows up, and there are no visible arrows, so the only way to move through it is through the thumbnails.

I am including the code for the script below.
I included #gallery2, #gallery3 and #gallery4 respectively with the exact same settings. But for some reason, #2, #3 and #4 are borked whereas #1 works.

Further below is the html code for the galleries themselves, and the script below.

$('#gallery').lbtLightBox({ qtd_pagination: 6, pagination_width: "160px", pagination_height: "160px", custom_children: ".boxport img", captions: true, captions_selector: ".caption p", }); $('#gallery2').lbtLightBox({ qtd_pagination: 6, pagination_width: "160px", pagination_height: "160px", custom_children: ".boxport img", captions: true, captions_selector: ".caption p", }); $('#gallery3').lbtLightBox({ qtd_pagination: 6, pagination_width: "160px", pagination_height: "160px", custom_children: ".boxport img", captions: true, captions_selector: ".caption p", }); $('#gallery4').lbtLightBox({ qtd_pagination: 6, pagination_width: "160px", pagination_height: "160px", custom_children: ".boxport img", captions: true, captions_selector: ".caption p", }); .boxport img { height: 200px } @font-face { font-family: 'Material Icons'; font-style: normal; font-weight: 400; src: url(https://fonts.gstatic.com/s/materialicons/v139/flUhRq6tzZclQEJ-Vdg-IuiaDsNc.woff2) format('woff2') } .material-icons { user-select: none; -webkit-user-select: none; cursor: pointer; font-family: 'Material Icons'; font-weight: 400; font-style: normal; font-size: 24px; line-height: 1; letter-spacing: normal; text-transform: none; display: inline-block; white-space: nowrap; word-wrap: normal; direction: ltr; -webkit-font-feature-settings: 'liga'; -webkit-font-smoothing: antialiased } #lbt-headertop, #lbt-thumbnails { color: #fff; list-style: none; margin: 0; padding: 0; transition: .3s } .lb-thumbnail-wrapper, .lt-thumbnail-wrapper { background: rgb(33 37 44 / 88%); left: 0; overflow: hidden; right: 0 } .lbr-ToFixed { overflow-y: hidden } #lbt-loading { width: 100px; height: 100px; margin: 20px; display: inline-block; z-index: 9; top: calc(50% - 50px); transform: translate(0, -50%); position: fixed } #lbt-lightbox_imgs { position: fixed; left: 0; top: 0; height: 100%; width: 100%; background: rgba(31, 35, 42, .8); z-index: 9999 } #lbt-lightbox_imgs img.image { box-shadow: 0 0 5px #00; width: 100% } #lbt-lightbox_imgs #lbt_lightbox-wrapper { position: relative; margin: 0 auto; max-width: calc(100% - 500px); max-height: calc(100% - 160px); z-index: 100 } #lbt-lightbox-media>* { max-height: calc(100% - 225px); top: calc(50% - 50px); transform: translate(-50%, -50%); position: fixed; object-fit: cover; max-width: 70vw } #lbt-lightbox-media>.lbt-iframe-video { width: 100%; aspect-ratio: 16/9 } #lbt-headertop { display: flex; width: 100%; height: 60px; position: relative; float: left; align-items: center; justify-content: center; overflow: hidden } #lbt-thumbnails { display: flex; height: 100px; position: -webkit-sticky; position: sticky; align-items: center; justify-content: center } #lbt-thumbnails li { justify-content: flex-start } .lb-thumbnail-wrapper { position: absolute; bottom: 0 } .lt-thumbnail-wrapper { position: absolute; top: 0 } ul li img.lbr-thumb { width: 60px; height: 60px; object-fit: cover; cursor: pointer; opacity: .9; transition: opacity .2s; border: 6px solid #515e66; margin-right: 7px } ul li img.lbr-thumb:hover { border: 6px solid #81868a; opacity: 1 } ul li img.lbr-thumb.active { border: 6px solid #cacaca; opacity: 1 } #lbt-name_lightbox { position: absolute; font-size: 16px; font-family: "Segoe UI"; color: #cacaca; left: 60px; top: 10px; cursor: pointer } #lbt-date_lightbox { position: absolute; font-size: 13px; font-family: "Segoe UI"; color: #838383; left: 60px; bottom: 10px; cursor: pointer } #lbt_next, #lbt_previous { margin-top: 0; font-size: 40pt; background: #262a31; border-radius: 50%; z-index: 1; color: #fff; top: 50%; cursor: pointer } #lbt-profile_lightbox { position: absolute; left: 0; height: calc(100% - 15px); cursor: pointer; padding: 5px } #lbt-profile_lightbox img { height: 100%; border-radius: 50% } #lbt-chat_lightbox { position: absolute; right: 320px; cursor: pointer } #lbt-star_lightbox { position: absolute; right: 270px; cursor: pointer } #lbt-smile_lightbox { position: absolute; right: 220px; cursor: pointer } #lbt-forward_lightbox { position: absolute; right: 170px; cursor: pointer } #lbt-download_lightbox { position: absolute; right: 120px; cursor: pointer } #lbt-dot_lightbox { position: absolute; right: 70px; cursor: pointer } #lbt-close_lightbox { position: absolute; right: 20px; cursor: pointer } .lbt-image-wrapper { position: relative; z-index: 1; display: flex; justify-content: center; align-items: center; left: 0 } #lbt_videoplayer .lbt_btn_play, #lbt_videoplayer .lbt_loadingVideo, .caption_text { left: 50%; transform: translate(-50%, -50%) } #lbt-lightbox-caption { font-family: Helvetica, Sans-Serif; font-weight: 400; line-height: 20px; margin-top: 15px; max-height: 57px; text-overflow: ellipsis; -webkit-line-clamp: 2; -webkit-box-orient: vertical; position: fixed; bottom: 90px; width: 70vw; text-align: center; overflow: hidden; color: #c8c8c9; display: block; display: -webkit-box; text-shadow: #262a31 1px 0 10px } #lbt_next, #lbt_previous, #lbt_videoplayer #captions.active, #lbt_videoplayer #settings.active { display: block } .hi-lightbox-thumbnail-active { height: 55px; border-bottom: 5px solid #fff } #lbt_next { position: absolute; right: 10px; width: 37px; padding-left: 25px } #lbt_previous { position: absolute; left: 0; width: 40px; padding-left: 20px } video::cue { opacity: 0 } .caption_text { position: absolute; bottom: 10%; width: 90%; max-width: 90%; text-align: center; user-select: none; transition: bottom .3s } #lbt_videoplayer { overflow: hidden } #lbt_videoplayer .lbt_btn_play { position: absolute; top: 50%; width: 20%; height: 20%; z-index: 1; stroke: #1c9dea; fill: #eff7fe; display: none } #lbt_videoplayer .lbt_btn_play:hover { stroke: #4d5961; fill: #e6f7f2; cursor: pointer } #lbt_videoplayer .lbt_loadingVideo { position: absolute; top: 50%; width: 60px; height: 60px; border: 4px solid #fff; border-bottom-color: transparent; border-radius: 50%; z-index: 1; animation: .6s linear infinite animate; display: none } #lbt_videoplayer .lbt_videoTime, #lbt_videoplayer .thumbnail { left: calc(var(--x) + 11px); transform: translateX(-50%); position: absolute; display: none } .lbt_vPlayPause { cursor: pointer } @keyframes animate { 0% { transform: translate(-50%, -50%) rotate(0) } 100% { transform: translate(-50%, -50%) rotate(360deg) } } #lbt_videoplayer .thumbnail { bottom: 80px; width: 165px; height: 90px; background: #fff; border: 2px solid #fff; border-radius: 3px } #lbt_videoplayer #lbt_vsrc { position: relative; width: 100%; height: 100%; outline: 0 } #lbt_videoplayer .lbt_videoTime { bottom: 50px; min-width: 60px; text-align: center; white-space: nowrap; padding: 5px 10px; color: #1c9dea; text-shadow: -1px -1px 0 #fff, 0 -1px 0 #fff, 1px -1px 0 #fff, -1px 0 0 #fff, 1px 0 0 #fff, -1px 1px 0 #fff, 0 1px 0 #fff, 1px 1px 0 #fff; font-size: 14px; font-weight: 400; z-index: 1 } #lbt_videoplayer .lbt_videoControls { position: absolute; bottom: 0; left: 0; height: 50px; width: 100%; background: rgb(0 0 0 / 29%); box-shadow: 0 0 40px 10px rgb(0 0 0 / 25%); z-index: 3; transform: translateY(180%); transition: .3s } #lbt_videoplayer .lbt_videoControls.active { transform: translateY(0) } #lbt_videoplayer .lbt_videoControls .video_progress-line { width: 100%; height: 5px; margin: auto; background: #f0f0f063; cursor: pointer; position: relative } .lbt_videoControls .video_progress-line .video_progress-bar { position: relative; width: 0%; background: #1c9dea; height: inherit; border-radius: inherit; cursor: pointer } .lbt_videoControls .video_progress-line .video_progress-bar::before { content: ""; position: absolute; width: 14px; height: 14px; border-radius: 50%; right: -15px; top: 50%; transform: translateY(-50%); background: #eff7fe; border: 3px solid #1c9dea } .lbt_videoControls .video_progress-line .video_buffer-bar { position: absolute; top: 0; right: 0; width: 100%; height: inherit } .lbt_videoControls .lbt_videoControls-list { display: flex; justify-content: space-between; align-items: center; flex-wrap: nowrap; width: 97%; height: 46px; margin: 0 auto } .lbt_videoControls .lbt_videoControls-list .lbt_videoControls-left, .lbt_videoControls .lbt_videoControls-list .lbt_videoControls-right { display: flex; justify-content: center; align-items: center } .lbt_videoControls .lbt_videoControls-left .timer { display: inline-block; font-size: 14px; white-space: nowrap; color: #fff; margin-left: 5px; text-align: center } .lbt_videoControls .icon { display: inline-flex; justify-content: center; align-items: center; text-align: center; color: #fff; margin-left: 8px; margin-right: 5px } .lbt_videoControls .icon .material-icons { font-size: 26px; color: #fff; cursor: pointer } .lbt_videoControls .icon .material-icons.lbt_fastRewind:active { transition: .2s; transform: rotate(-45deg) } .lbt_videoControls .icon .material-icons.lbt_fastForward:active { transition: .2s; transform: rotate(45deg) } .lbt_videoControls .icon .lbt_videoVolumeRange { -webkit-appearance: none; appearance: none; width: 0; height: 3px; background: #fff; color: #fff; cursor: pointer; outline: 0; border: none; transition: .4s } .lbt_videoControls .icon .lbt_videoVolumeRange::-webkit-slider-thumb { -webkit-appearance: none; appearance: none; width: 12px; height: 12px; border-radius: 50%; border: none; outline: 0; background: #fff; color: #fff; opacity: 0; transition: .3s } .lbt_videoControls .icon:hover .lbt_videoVolumeRange { display: inline-block; width: 60px } .lbt_videoControls .icon:hover .lbt_videoVolumeRange::-webkit-slider-thumb { opacity: 1; pointer-events: auto; transition: .5s } .lbt_videoControls-right .icon .lbt_videoAutoPlay { width: 30px; height: 10px; border-radius: 20px; position: relative; margin-right: 8px !important; background: #b6b6b6 } .lbt_videoControls-right .icon .lbt_videoAutoPlay::before { content: "\e034"; position: absolute; left: -5px; top: 50%; transform: translateY(-50%); width: 17px; height: 17px; line-height: 17px; font-size: 14px; background: #727272; display: flex; justify-content: center; align-items: center; cursor: pointer; border-radius: 50%; font-family: "Material Icons" } .lbt_videoControls-right .icon .lbt_videoAutoPlay.active::before { content: "\e037"; left: 15px; font-family: "Material Icons" } .lbt_videoControls-right .icon .material-icons.settingsBtn { font-size: 24px; transition: .3s } .lbt_videoControls-right .icon .settingsBtn.active { transform: rotate(45deg) } #lbt_videoplayer #captions, #lbt_videoplayer #settings { right: 25px; position: absolute; bottom: 62px; background: rgb(28 28 28 / 90%); width: 200px; max-height: 250px; height: auto; color: #fff; overflow-y: auto; z-index: 20; display: none; border-radius: 5px } #lbt_videoplayer #captions .caption span, #lbt_videoplayer #settings>div>span { font-size: 14px; font-weight: 300; padding: 15px 30px; border-bottom: 1px solid #535353; display: flex; justify-content: space-between; align-items: center; white-space: nowrap } #lbt_videoplayer #settings>div .icon { font-size: 14px; margin: 0 5px; cursor: pointer } #lbt_videoplayer #settings>div ul li span { pointer-events: none } #lbt_videoplayer #captions .caption ul, #lbt_videoplayer #settings>div ul { position: relative } #lbt_videoplayer #captions .caption ul li, #lbt_videoplayer #settings>div ul li { position: relative; width: 100%; cursor: pointer; text-align: left; padding: 12px 33px; display: flex; justify-content: space-between; align-items: center; font-size: 14px } #lbt_videoplayer #captions .caption ul li:hover, #lbt_videoplayer #settings>div ul li:hover { background: rgba(28, 28, 28, .9) } #lbt_videoplayer #captions .caption ul li.active::before, #lbt_videoplayer #settings>div ul li.active::before { content: "\e876"; font-family: "Material Icons"; position: absolute; left: 7px; top: 50%; transform: translateY(-50%); padding-right: 10px; font-size: 18px } #lbt_videoplayer #captions::-webkit-scrollbar, #lbt_videoplayer #settings::-webkit-scrollbar { width: 8px; background: 0 0 } #lbt_videoplayer #captions::-webkit-scrollbar-thumb, #lbt_videoplayer #settings::-webkit-scrollbar-thumb { height: 20px; border: 2px solid transparent; background: rgba(83, 83, 83, .9); border-radius: 20px } @media (max-width:430px) { .container { width: 100%; display: flex; justify-content: center; align-items: center } .lbt_videoControls .icon { margin-left: 5px; margin-right: 5px; font-size: 24px } .lbt_fastForward, .lbt_videoAutoPlay, .lbt_videoPip, .lbt_videoVolume, .lbt_videoVolumeRange { display: none } } <script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.7.1/jquery.min.js"></script> <div class="row collapse multi-collapse" id="multiCollapseExample1"> <div class="containerport"> </div> <div id="gallery"> <div class="boxport"> <img src="https://www.cri8ive.it/portfolio/51.jpg" alt="Restyling Sito - Dreamline" title="Restyling Sito - Dreamline"> <div class="caption"> <p> <a href="https://www.rprepository.com/g/dreamline-rpg/14361" target="_blank" style="color:#e00101; text-decoration:underline;">Restyling Sito</a><br> <span style="font-weight:normal;">2024</span> </p> </div> </div> <div class="boxport"> <img src="https://www.cri8ive.it/portfolio/46.jpg" alt="Restyling Sito - Bon Ton Bar" title="Restyling Sito - Bon Ton Bar"> <div class="caption"> <p> <a href="http://bontonbar.altervista.org" target="_blank" style="color:#e00101; text-decoration:underline;">Restyling Sito</a><br> <span style="font-weight:normal;">2024</span> </p> </div> </div> <div class="boxport"> <img src="https://www.cri8ive.it/portfolio/44.jpg" alt="Restyling Sito - Laboratorio Napoletano" title="Restyling Sito - Laboratorio Napoletano"> <div class="caption"> <p> <a href="https://www.labonapo.it" target="_blank" style="color:#e00101; text-decoration:underline;">Web Design</a><br> <span style="font-weight:normal;">2024</span> </p> </div> </div> <br> <br> <br> </div> </div> <!-- Grafica --> <div class="row collapse multi-collapse" id="multiCollapseExample2"> <div class="containerport"> </div> <div id="gallery2"> <div class="boxport"> <img src="https://www.cri8ive.it/portfolio/62.jpg" alt="Biglietto da visita - Federica Pelle Psicologa" title="Biglietto da visita - Federica Pelle Psicologa"> <div class="caption"> <p> <a href="https://www.federicapelle.it" style="color: red; text-decoration: underline;" target="_blank">Biglietto da visita</a><br> <span style="font-weight:normal;">2026</span> </p> </div> </div> <div class="boxport"> <img src="https://www.cri8ive.it/portfolio/61.jpg" alt="Biglietto di auguri" title="Biglietto di auguri"> <div class="caption"> <p> Graphic<br> <span style="font-weight:normal;">2025</span> </p> </div> </div> <div class="boxport"> <img src="https://www.cri8ive.it/portfolio/58.jpg" alt="Flyer - Namumste" title="Flyer - Namumste"> <div class="caption"> <p> <a href="https://www.afetaquilone.org/" style="color: red; text-decoration: underline;" target="_blank">Volantino</a><br> <span style="font-weight:normal;">2025</span> </p> </div> </div> <br> <br> <br> </div> </div> <!-- Cover Design --> <div class="row collapse multi-collapse" id="multiCollapseExample3"> <div class="containerport"> </div> <div id="gallery3"> <div class="boxport"> <img src="https://www.cri8ive.it/portfolio/60.jpg" alt="Cover Art - Il Diritto di Disobbedire" title="Cover Art - Il Diritto di Disobbedire"> <div class="caption"> <p> <a href="https://www.amazon.it/Diritto-Disobbedire-Potere-Ribellione-allOdissea-ebook/dp/B0F2MD5LX4/ref=sr_1_1?__mk_it_IT=%C3%85M%C3%85%C5%BD%C3%95%C3%91&crid=1EZ6RZC9SHT14&dib=eyJ2IjoiMSJ9.jCc1PzhSer7JUwMH9m3v3A.NqS1S5O9Mqqov0savN1FwSmHJFZRLL_UD84qpvvcy7Q&dib_tag=se&keywords=Il+diritto+di+disobbedire&qid=1744199132&s=books&sprefix=il+diritto+di+di%2Cstripbooks%2C511&sr=1-1" style="color: red; text-decoration: underline;" target="_blank">Cover Art</a><br> <span style="font-weight:normal;">2025</span> </p> </div> </div> <div class="boxport"> <img src="https://www.cri8ive.it/portfolio/47.jpg" alt="Cover Design - L'Evangelo di Maria Valtorta" title="Cover Design - L'Evangelo di Maria Valtorta"> <div class="caption"> <p> <a id="blankcover2">Cover Design</a><br> <span style="font-weight:normal;">2024</span> </p> </div> </div> <div class="boxport"> <img src="https://www.cri8ive.it/portfolio/45.jpg" alt="Cover Design - Storia di un'anima" title="Cover Design - Storia di un'anima"> <div class="caption"> <p> <a id="blankcover1">Cover Design</a><br> <span style="font-weight:normal;">2024</span> </p> </div> </div> <br> <br> <br> </div> </div> <!-- Artwork --> <div class="row collapse multi-collapse" id="multiCollapseExample4"> <div class="containerport"> </div> <div id="gallery4"> <div class="boxport"> <img src="https://www.cri8ive.it/portfolio/65.jpg" alt="Artwork - Curse of the Witch" title="Artwork - Curse of the Witch"> <div class="caption"> <p> <a id="artwork9">Artwork</a><br> <span style="font-weight:normal;">2026</span> </p> </div> </div> <div class="boxport"> <img src="https://www.cri8ive.it/portfolio/64.jpg" alt="Artwork - Heartbreak VS Lovestruck" title="Artwork - Heartbreak VS Lovestruck"> <div class="caption"> <p> <a id="artwork8">Artwork</a><br> <span style="font-weight:normal;">2026</span> </p> </div> </div> <div class="boxport"> <img src="https://www.cri8ive.it/portfolio/63.jpg" alt="Coloring - Fantasy" title="Coloring - Fantasy"> <div class="caption"> <p> <a id="artwork7">Colorazione</a><br> <span style="font-weight:normal;">2026</span> </p> </div> </div> <br> <br> <br> </div> </div> <script src="https://code.jquery.com/jquery-4.0.0.min.js"></script> <script src="https://www.cri8ive.it/js/jquery.lbt-lightbox.js"></script>
Read Entire Article