mardi 7 juin 2016

JS - Detect Touch device didnt work API 3

I try to detect if the user device is a touch screen but when i do with 'ontouchstart' in window condition dont work well.

I try to desable the dragg only for touch screen device (I hope this is the better solution for a full width gmap in mobile for avoid the scroll bug in touch)

Can you help me to find the problem ? I've checked a lot of Starkoverflow subject but in dont find the good solution i'm blind maybe.

 function initMap() {
    var map;
    var bounds = new google.maps.LatLngBounds();

    if ('ontouchstart' in window){
    var isDraggable = !("ontouchend" in document);
    }
    else {
    var isDraggable = !('ontouchstart' in document.documentElement);
    }
    var mapOptions = {
        mapTypeId: 'roadmap',
        styles: WHITE,
        draggable: isDraggable,
        scrollwheel: false,
    };

Thanks for helping !

Aucun commentaire:

Enregistrer un commentaire