简体   繁体   中英

JS onMouseDown and onMouseUp events Safari iPhone: can not make them working

I'm using iPhone with iOS 10.3.2(14F89) and its correspondent Safari.

My goal is: when the user starts tapping (presses) an image I need to receive "onMouseDown" event and when he/she finishes tapping the image I need to receive "onMouseUp" (released) event.

After searching and making lots of tests with following code:

<style>
   body { -webkit-touch-callout: unset !important; }
   img  { -webkit-user-select: none !important; } 
</style>

<body>
   <img src="an_image.png" onMouseDown="onPressed()" onMouseUp="onReleased()">
</body>

<script>
    function onPressed()
    {
        console.log( "pressed" );
    }

    function onReleased()
    {
        console.log( "released" );
    }
</script>

But the contextual menu always appear or at least the magnifier. I tried also other "-webkit" directives with no luck.

Thank you very much in advance for your help.

You might want to check the link: https://developer.mozilla.org/en/docs/Web/API/Touch_events

the onMouseDown and onMouseUp are usually mouse events and you would always want to use touch events to handle touch events

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