문제

This is the first time I'm working with touch events. What I'm making is a button to slide a side menu on a responsive web. The button should only show it a touchstart event exists and dissapear 500ms after the touchend event is triggered.

here is my code:

// EVENT LISTENERS

function touchDown(event) {
    sliderButton.show();
}

function touchUp(event) {
    sliderButton.hide();
}

if (isMobile.any()) {
    sliderButton.hide();
    window.addEventListener("touchstart", touchDown, false);
    window.addEventListener("touchend", setTimeout(function() {
        sliderButton.hide(); //I used to invoke the touchUp function and it also didin't work, 
    }, 500), false);

}

Also when I do touchmove (basically just move my finger areound the screen) it doesn't recognize the 'touchend' trigger. Any cluues on how to deal with thhis? Or should I open a new thread for that?

Thanks

도움이 되었습니까?

해결책

I'm going to answer this instead of erasing the question because I found the same problem on other forums.

Basically that code works. I don't know why it happens sometimes that it doesn't work after a while. Even emptying the cache deson't help solve this.

It really makes no sense to me but I thought that since no one has answered others might benefit from trying to reset their pageload somehow and try it again.

cheers!

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top