Hover and click event on mobile devices

前端 未结 3 1437
滥情空心
滥情空心 2020-12-08 23:00

I am creating a responsive website for both desktop and mobile. I have one issue with a hover and click event that I am not sure how to solve for users on mobile devices.

3条回答
  •  醉梦人生
    2020-12-09 00:01

    if (('ontouchstart' in window || (window.DocumentTouch && document instanceof DocumentTouch))) {
        $(".touch")
            .bind("touchstart", function() {
                $(this)
                    .addClass("active")
                    .bind("touchend", function() {
                        $(this).removeClass("active");
                    });
            })
            .bind("touchenter", function() {
                $(this)
                    .addClass("hover")
                    .bind("touchleave", function() {
                        $(this).removeClass("hover active");
                    });
            });
    }
    

提交回复
热议问题