1

I'm coding a calendar in JavaScript for my website.

I've added a feature with mouse events that allow user to click and slide to find expect date. It works well.

My problem is when I try to do it on smartphone. I use touch start/move/end in place of mouse down/move/end.

But touchmove is not triggered when the touch was started on element that is finally remove of dom.

Is this normal behavior ?

You can try this codepen on smartphone or emulate with F12 console. when start a touchmove on red div, counter touchmove will count, but when red div dropped of dom, counter stop. then I cannot detect touchmove anymore.

var counter_factory = function (el_id) {
    var count = 0;
    var el = document.getElementById(el_id);
    return function () {
        el.innerHTML = el_id +' '+ count++;
    };
};
var mouse_count = counter_factory('mousemove');
var touch_count = counter_factory('touchmove');
mouse_count();
touch_count();

var listen_el_list = function (el_list, ev, func) {
    el_list.forEach(function (el) {
        el.addEventListener(ev, func, false);
        el.addEventListener(ev, func, true);    
    });
};
var div_cover = document.getElementById('cover');
var el_list = [window, document, document.body, div_cover];
listen_el_list(el_list, 'mousemove', mouse_count);
listen_el_list(el_list, 'touchmove', touch_count);
user2402622
  • 93
  • 1
  • 6

0 Answers0