简体   繁体   中英

ontouchstart not working on Windows 8 Tablet

I'm trying to get ontouchstart working for windows tablet. If detected it disables the top layer of my links so that a click event allows the menu to remain open (instead of a hover effect).

The following code is working on other touch devices so I'm not sure if there is anything else I need to do?

 $topLink.on('click', function (e) {

        $dropDown.removeClass('child');
        $dropDown.not($(this).next('.dropdown')).removeClass('open');
        $topLink.not($(this)).removeClass('active-link');

        $(this).next('.dropdown').toggleClass('open');
        $(this).toggleClass('active-link');

        if (("ontouchstart" in document.documentElement) || ($window.width() < 1120)) {
            // disable top level links for touch
            e.preventDefault();
            e.stopPropagation();
        }

    });

IE/Edge has no TouchEvents (at least not enabled by default), it has PointerEvents .

Have a look at caniuse.com: PointerEvents TouchEvents

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM