Ecommerce Shopify WordPress Discussion

Download image flashes open on load when it should be closed

I have created a button to show am image when clicked at the bottom of my website. I have included the code below. The issue is that the image flashes and is shown open when I load the page. How can I fix that issue? <style> /* -------- DOWNLOAD OUR APP -------- */ .byok-container { margin-left: 2rem; margin-right: 2rem; background-color: #22262b; width: 100%; height: 100%; z-index: 1000; } .byok-popup { display: none; } .popup-button { display: none; } .open-text { display: none; } /* Show popup */ .show-popup { display: grid; } .show-popup .byok-popup-content { transform: scale(1) translateY(0); } /* -------------- BREAKPOINTS -------------- */ @media screen and (min-width: 700px) { /*.mobile-text { display: none; }*/ .byok-popup-content { position: fixed; right: 40px; bottom: 13px; z-index: 30000; margin-top: 5px; background-color: #CFA240; text-align: center; padding: 0.3rem; border-radius: 20px; transition: all 0.3s; transform: translateY(10%); } .byok-open { background-color: #CFA240; position: fixed; bottom: 5px; right: 10px; z-index: 100; border-radius: 40px; } .mobile-button { display: none; } .byok-container { margin-left: 1rem; margin-right: 1rem; background-color: transparent; height: 0; width: 0; position: fixed; display: flex; justify-content: center; align-items: center; } .open-text {display: inline;} .byok-popup-container { overflow: scroll; transition: all 0.3s; z-index: 1000; background-color: transparent; width: 100%; height: 0%; display: block; } .popup-button { display: inline-block; background-color: #CFA240; color: #fff; padding: 1rem 1.25rem; margin: 0.5rem; transition: 0.3s; text-align: left; border: none; } .open-text { font-family: "Josefin Sans", sans-serif; font-size:16px; padding: 5px 8px; margin: 0; } .byok-popup-close { display: inline-flex; color: #fff; font-size: 2rem; position: absolute; top: 0.9rem; right: 1.5rem; margin: 0; cursor: pointer; z-index: 500; line-height: 30px; } .byok-popup-content { margin: auto; width: 300px; border-radius: 1.75rem; } .popup-img { width: 50px; } .byok-open { right: 40px; } .byok-close { font-size: 50px; font-weight: 200; color: #fff; } } </style> Here is the button and javascript: <button class="popup-button byok-open" id="open-popup"> <p class="open-text">DOWNLOAD OUR APP</p> </button> <div class="byok-popup byok-container" id="popup-container"> <!-- Main Container --> <div class="byok-popup-container"> <!-- Popup Container --> <div class="byok-popup-content"> <!-- Popup Content --> <div class="byok-popup-close" title="Close" id="byok-top-close"> <div class="byok-close">×</div> </div> <img src="/img.php" alt="app QR code, scan to go to your app store"> </div> </div> </div> <script> const popupContainer = document.getElementById("popup-container"); const byokButton = document.getElementById("open-popup"); const popup = document.querySelector(".byok-popup"); // Open Popup const showPopup = () => { sessionStorage.setItem('BYOK Activity', 'Active'); popupContainer.classList.add('show-popup'); byokButton.style.display = 'none'; popup.style.display = 'grid'; // Add close buttons const closeX = document.getElementById("byok-top-close"); closeX.addEventListener('click', closePopup); }; byokButton.addEventListener("click", showPopup); // Close Popup const closePopup = () => { sessionStorage.setItem('BYOK Activity', 'Inactive'); popupContainer.classList.remove('show-popup'); if (window.innerWidth >= 700){ byokButton.style.display = "block"; } popup.style.display = "none"; } // Check browser width | Remove popup if mobile const byokPopupActivity = () => { if ((window.innerWidth >= 700) && sessionStorage.getItem('BYOK Activity') === 'Active') { showPopup(); return; } closePopup(); sessionStorage.setItem('BYOK Activity', 'Inactive'); } byokPopupActivity(); </script> Ive tried searching online for any similar issues but I couldn't find any.
Your code worked fine for me and an image that I linked locally did not flash when loading the page. My recommendation if you are still having this issue is to set display: none for the image in your css and then set display: block on that image when you call the showPopup function. Hope this helps!

February 17, 2024

TurboCommerce make the better internet purchasing globaly

Turbo Multi-language Translator

Make the better internet purchasing globaly

Turbosify SEO Speed Booster

5.0 (7) Free plan available
Get better conversions by improving store loading speed Installed

Turbo Multi-language Chat - AI Customer service in one hand

TurboCommerce make the better internet purchasing globaly
Our products

The help you need, when you need it

App by Turbo Engine

3 apps • 5.0 average rating

Turbosify Speed Booster

5.0 (7)
Get better conversions by optimizing shopify store Google page speed Installed

Turbosify Translator for Wordpress Woocommerce

5.0 (74) Free Wordpress Woocommerce Plugin
Translate your wordpress website to multiple language within 1 click, no configuration needed, no No technical required

Grow your business here

Whether you want to sell products down the street or around the world, we have all the tools you need.