Viewing 12 posts - 1 through 12 (of 12 total)
  • Author
    Posts
  • #1492503

    On this page that I created with your very useful help, swiping on mobile devices changes the image, making it out-of-sync with the selected item in the ingredients list. How can I block user swiping? I cannot disable the Easy Slider navigation controls (set it to no user interaction) because the item selection code in the ingredient list needs them to display the corresponding image.

    Best regards,
    Serge Froment

    #1492504

    Hey photographie-tous-azimuts,
    Try adding this css:

    /* Disable touch/swipe on mobile */
    @media (max-width: 768px) {
        .slider-container,
        .slider-container * {
            touch-action: none !important;
            -webkit-user-drag: none !important;
            user-select: none !important;
        }
    }

    Then clear your cache and check. Unfortunately I can not test this on my end as desktop browser doesn’t show the swipe action, but this will likely work.
    If you are using a iPhone you may need to clear the history to fully clear the cache.

    Best regards,
    Mike

    #1492505

    Hi,
    Or try this css:

    
    /* Disable touch/swipe on mobile */
    @media (max-width: 768px) {
        .avia-slideshow,
        .avia-slideshow * {
            touch-action: none !important;
            -webkit-user-drag: none !important;
            user-select: none !important;
        }
    }

    Best regards,
    Mike

    #1492507

    Hi,

    I tried both to no avail. I did use (max-width: 1024px) to include iPad. I cleared the cache on Safari and also used Brave browser, which I never used for that web site on that device.

    Best regards,
    Serge

    #1492544

    Hi,
    Thanks for the feedback, I can only test on a Android device, but will need an admin login to apply the code and then test on my device.
    Please add the admin login in the private comment below.

    Best regards,
    Mike

    #1492546

    Here it is.

    #1492578

    Hi,
    Thanks, I added this script to your child theme functions.php file:

    function remove_slideshow_swipe_script() { ?>
      <script>
    document.addEventListener('DOMContentLoaded', function() {
        if (window.innerWidth <= 768) {
            var slideshow = document.querySelector('.avia-slideshow');
            if (slideshow) {
                slideshow.style.touchAction = 'none';
                
                ['touchstart', 'touchmove', 'touchend'].forEach(function(event) {
                    slideshow.addEventListener(event, function(e) {
                        e.preventDefault();
                        e.stopImmediatePropagation();
                    }, {passive: false, capture: true});
                });
            }
        }
    });
      </script>
      <?php
    }
    add_action( 'wp_footer', 'remove_slideshow_swipe_script', 99 );

    and it is working for my Android device, with the other script still working, as before if you are using a iPhone you may need to clear the history to fully clear the cache.

    Best regards,
    Mike

    #1492579

    Hi,

    It does works, but it prevents scrolling the page when touching the image. Not a major problem, but it feels a bit strange (like Google Maps that zooms in/out when we try to scroll). Since the same swiping problem occurs on iPad too, it is more likely someone will try to scroll the page from the (larger) image there.

    Maybe we should do it the other way around: allow swiping and update the selected ingredient when that happens.

    Best regards,
    Serge

    #1492586

    Hi,

    Thank you for the update.

    We updated the script in the functions.php file — the page should now be scrollable.

    function remove_slideshow_swipe_script() { ?>
    <script>
    document.addEventListener('DOMContentLoaded', function() {
        if (window.innerWidth <= 768) {
            var slideshow = document.querySelector('.avia-slideshow');
            if (!slideshow) return;
    
            slideshow.style.touchAction = 'pan-y';
    
            let startX = 0;
            let startY = 0;
    
            slideshow.addEventListener('touchstart', function(e) {
                startX = e.touches[0].clientX;
                startY = e.touches[0].clientY;
            }, {passive: true, capture: true});
    
            slideshow.addEventListener('touchmove', function(e) {
                const dx = Math.abs(e.touches[0].clientX - startX);
                const dy = Math.abs(e.touches[0].clientY - startY);
    
                if (dx > dy) {
                    e.preventDefault();
                    e.stopImmediatePropagation();
                }
            }, {passive: false, capture: true});
        }
    });
    </script>
    <?php
    }
    add_action( 'wp_footer', 'remove_slideshow_swipe_script', 99 );
    
    

    Best regards,
    Ismael

    #1492623

    Hi Ismael,

    Thank you so much. It works like a charm. I did up the window width test to 1440px to include all touch devices: iPad, Android tablet and MS Surface. (Do I really need that test? Non-touch devices will not encounter touch events, right?)

    Best regards,
    Serge

    #1492633

    Hi,
    Glad that Ismael could help, you are correct that non-touch devices will not encounter touch events, so it should not be an issue. Unless there is anything else with this issue, shall we close this thread? Naturally you can always open a new thread for new issues, but we like to keep each thread on topic. :)

    Best regards,
    Mike

    #1492637

    Hi,
    Yes, you can close the thread.
    Thanks.

    Best regards,
    Serge

Viewing 12 posts - 1 through 12 (of 12 total)
  • You must be logged in to reply to this topic.