Prevent link clicking if scrolling on mobile device

I have a long vertical list of links that the user can scroll through, and I need to prevent the event click(touch) from triggering on these links if the user scrolls.

In the current scenario, when the user starts scrolling by clicking on the link, he also launches the link clickby link. Which is clearly bad. So, is there a way to prevent this behavior?

+4
source share
1 answer

Working violin

, click .

jQuerys, DOM setTimeout(), 250ms, , :

var disable_click_flag = false;

$(window).scroll(function() {
    disable_click_flag = true;

    clearTimeout($.data(this, 'scrollTimer'));

    $.data(this, 'scrollTimer', setTimeout(function() {
        disable_click_flag = false;
    }, 250));
});

$("body").on("click", "a", function(e) {
    if( disable_click_flag ){
        e.preventDefault();
    }
});

, .

+4

All Articles