Issue with product hover / image swap feature

This topic has 6 replies, 2 voices, and was last updated 2 months, 2 weeks ago ago by Jack Richardson

  • Avatar: Niddy
    Niddy
    Participant
    September 15, 2025 at 15:34

    Hi,

    Using this theme – and on products – whether archive / carousel / grid etc – you have an image swap facility.

    Now, I’ll try and make this simple otherwise it’ll get confusing.

    The images on my clients site aren’t what you’d call normal. For ease, let’s say they sell carpets. So some are square and others aren’t – like doormat runners are long and thin.

    Problem is; they didn’t sort dimensions properly when they added products and here we are now with over 100,000 images so it’s impossible to redo them all.

    So, my issue here is I’ve ran a script that basically shrunk the largest pixel to 1500px and made it square so all images are at least 1500x1500px – this was an image edit script so we done this and reloaded images. All fine.

    So, standard image cropping is fine as it’s only cropping the white borders technically and reducing from 1500 -> 300 etc for the archive.

    That’s all great and no issues here.

    However;

    The problem is the image swap / hover facility. It seems this is coded incorrectly as in hard coded somewhere as no matter what I do from a hook into your hover-swap to override it in child theme to adding js to aggressive css seems to have any effect.

    All I need is for the image swap / hover image *only* (not the main product image) to work differently so it starts from centre/middle pixel and works outwards as a cover; keeping the dimensions – so it always fills the hover placement on the archive / carousel / grid etc and hides the white borders that’s now present by default on all images.

    Can you please advise how to target this element or how to make it count from centre / middle outwards so it keeps dimensions of the layout and fills the space? It’s madness as it really does look like you force via script that it rebuilds the swap images dynamically and overrides any changes.

    Example – The swap < span > and < img> are dynamically inserted and cloned by the theme’s JavaScript after the page fully loads so even MutationObserver fails because XStore uses your own internal functions to rebuild the HTML on hover/slide events.

    For instance this should fix it but has zero effect –

    function xstore_hover_swap_fix() {
        ?>
        <script>
        (function() {
            'use strict';
    
            // This function applies object-fit cover to hover swap images
            function fixHoverSwap() {
                document.querySelectorAll('.etheme-product-hover-swap-image img').forEach(function(img){
                    if (img.dataset.__fixed) return;
    
                    // Make the img fill its container and crop from center
                    img.style.width = '100%';
                    img.style.height = '100%';
                    img.style.objectFit = 'cover';
                    img.style.objectPosition = 'center center';
                    img.style.display = 'block';
    
                    img.dataset.__fixed = '1';
                });
            }
    
            // Run after window load (ensures XStore slider has initialized)
            window.addEventListener('load', fixHoverSwap);
    
            // Observe for DOM changes (lazy load / slider clones)
            var observer = new MutationObserver(fixHoverSwap);
            observer.observe(document.body, { childList: true, subtree: true });
    
            // Also fix on resize
            window.addEventListener('resize', fixHoverSwap);
        })();
        </script>
        <?php
    }
    add_action('wp_footer', 'xstore_hover_swap_fix', 100);

    Thanks

    5 Answers
    Avatar: Jack Richardson
    Jack Richardson
    Support staff
    September 15, 2025 at 18:04

    Dear @Niddy,

    We hope this message finds you well.

    Could you kindly provide us with the URL of the page where the issue is occurring, along with a video demonstrating the problem? At the moment, we can see that most of the images on your shop page appear to be displaying correctly.

    As we understand it, you would like the swap image to have custom dimensions and not be stretched to match the main image. If that is the case, you may consider using the following custom CSS to achieve the desired effect:

    body .etheme-product-hover-swap-image {
        position: static;
    }
    
    body .etheme-product-grid-image:not(:hover) .etheme-product-hover-swap-image {
        opacity: 1;
        visibility: visible;
        display: none;
    }
    
    body .etheme-product-grid-image:hover img:has(+.etheme-product-hover-swap-image) {
        display: none;
    }

    Please let us know if this helps or if you need further assistance.

    Best regards,
    The 8Theme Team

    Avatar: Niddy
    Niddy
    Participant
    September 15, 2025 at 18:34

    Hi

    This css would actually break. Example,

    has() is not supported in most browsers yet (only Chrome/Safari with experimental flags) – so it won’t work in Firefox, Edge, or stable Chrome builds – ie the hover image won’t ever swap in most cases.

    Plus, your rule ie

    body .etheme-product-hover-swap-image {
        position: static;
    }

    That will actually break your hover swap overlay logic, because that < span> is absolutely positioned by default to sit on top of the main image. Making it static pushes it back into the normal flow so everything shifts!

    This approach still doesn’t solve the “white borders” problem. Even if the swap shows, it’ll still be letterboxed inside the square unless we use force object-fit: cover; ie

    .etheme-product-hover-swap-image img {
        width: 100% !important;
        height: 100% !important;
        object-fit: cover !important;
        object-position: center center !important;
        display: block;
    }

    That’s what I’m trying to say here. 🤷‍♂️

    I want it to stretch on image swap / hover only – but based on centre – middle -> outwards. We need to use cover.

    Avatar: Jack Richardson
    Jack Richardson
    Support staff
    September 15, 2025 at 19:26

    Hello @Niddy,

    If you have found that using object-fit: cover resolves your issue, we are glad to hear that your request has been successfully addressed. However, if you still require our assistance, we would greatly appreciate it if you could provide additional clarification—such as screenshots or a video—to help us better understand your request.

    Best regards,
    The 8Theme Team

    Avatar: Niddy
    Niddy
    Participant
    September 16, 2025 at 12:41

    Hi

    Its not been properly addresses as I explained – the js I added should fix it but it cannot due to the mis-configuration within the actual coding of the element.

    So I am asking how we can hook into it properly so I can achieve the desired outcome?

    Thanks

    Avatar: Jack Richardson
    Jack Richardson
    Support staff
    September 16, 2025 at 13:35

    Hello @Niddy,

    Thank you for reaching out to us.

    We apologize, but we are still unable to fully understand the issue you are experiencing. If you are referring to the small white gap that appears on hover compared to the original images, you may be able to resolve this by applying the following custom CSS:

    .etheme-product-hover-swap-image img {
        --image-scale: 1.2;
    }

    If this is not the issue you are referring to, we kindly ask that you provide us with screenshots clearly indicating the problem, preferably with arrows or annotations for better clarity.

    We appreciate your cooperation and look forward to assisting you further.

    Best regards,
    The 8Theme Team

  • Viewing 6 results - 1 through 6 (of 6 total)

You must be logged in to reply to this topic.Log in/Sign up

We're using our own and third-party cookies to improve your experience and our website. Keep on browsing to accept our cookie policy.