Toggle div on click or touch and hide on click/touch outside

前端 未结 3 1186
予麋鹿
予麋鹿 2021-01-24 05:10

I\'m trying to support both mouse and touch events for a div that I want to show and hide. My mouse events work well, but I\'m not sure of how to get this to work on a touch-bas

3条回答
  •  再見小時候
    2021-01-24 06:04

    This is enough: JsFiddle

    $searchTrigger.on('click', function(e) {
        $searchBox.toggle();
        e.preventDefault();
    });
    

    it works for screen and touch devices.

提交回复
热议问题