2017-06-23 9 views
0

Je développe un site où j'utilise la bibliothèque Pjax (un port de jquery pjax). Cependant, les événements tactiles ne passent pas. J'utilise Pjax comme ceci:Comment activer les événements tactiles sur la bibliothèque pjax?

var pjax = new Pjax({ selectors: ["head title", "body"] }) 

et aussi des animations:

document.addEventListener('pjax:send', function(){ 
    var $main = document.querySelector('main') 
    $main.style.opacity = 0 
}) 

document.addEventListener('pjax:complete', function(){ 
    var $main = document.querySelector('main') 
    $main.style.visibility = 'hidden' 
    $main.style.opacity = 0 
    setTimeout(function(){ 
    document.querySelector('main').style.visibility = 'visible' 
    document.querySelector('main').style.opacity = 1 
    attach_menu_control() 
    }, 10) 
}) 

je en ai besoin de travailler sur mobile. Le site est www.saulesinterjerai.lt (peut être bogué)

Répondre

0

J'ai trouvé la solution, il fonctionne en redirigeant événement tactile pour cliquer sur l'événement comme celui-ci:

if (is_touch_device()) { 
    var all_links = document.querySelectorAll('a[href]') 
    var event = new Event('click'); 

    for (var index = 0 ; index < all_links.length ; ++index) { 
    all_links[index].addEventListener("touchend", function() { 
     all_links[index].dispatchEvent(event) 
    }); 
    } 
} 

function is_touch_device() { 
    return 'ontouchstart' in window  // works on most browsers 
     || navigator.maxTouchPoints;  // works on IE10/11 and Surface 
}