Manipulation and Touch events not firing, but mouse events do?

情到浓时终转凉″ 提交于 2019-12-01 09:23:06

问题


I have a Samsung LD220Z multi touch monitor, and when I'm experimenting with some WPF and touch features the touch events arent firing. The mouse down event seems to be firing however.

Does this mean that I have to take into account that not all touch screen behave the same, and how do I get the touch inputs on my screen? I've tried the Windows 7 Touch pack that microsoft released. And the multi touch features seems to work there.

Any suggestion on how to proceed with this?


回答1:


Event touchstart WORKS but touchend not. You can use onmouseup="SOMEfun()" Even the Samsung Galaxy 3 is a problem with the trigger event. Add the first event and thay will be working on but Two scenario : 1)first add onmouseup and than tauchstart or better 2)check mobile or desktop and than add proper events You can use my detectbrowser function , its very nice (give a name of browser type like mobile_chrome_android_tablet or firefox_desktop , safari_ipad)

Make NOMOBILE global , you can simply replace var NOMOBILE =0; with window["NOMOBILE"]=0;

download browser and device detector : detect browser and device also class

Class name is DETECTBROWSER()

(on first line in script)

var BROWSER = new DETECTBROWSER()

Check this BROWSER.NAME

This is even crazy't script . Track 10 fingers at same time (in canvas2d) link : https://github.com/zlatnaspirala/multi-touch-canvas-handler

example for 1)

      document.getElementById('myCanvas').addEventListener('touchstart', function(event) {
         event.preventDefault(); 
        var touch = event.touches[0]; 
        /* Avatar go left */
          if (touch.pageX < 235) {
        if (backgroundX < 0){
         left = 1;
         }
        /* Avatar go right */
         if (touch.pageX > 470) {
         right=1;
         }
        /* Avatar go lower distance */
         if (touch.pageX > 235 && touch.pageX < 470 && touch.pageY >250 ) {
         distance--;
         }
        /* Avatar go to high distance */
         if (touch.pageX > 235 && touch.pageX < 470 && touch.pageY <250 )  {
         distance++; 
        }
         } ,false);
        // solution for touchend
          function ENDoff(){

           if (moveLEFT==1) {  moveLEFT=0;  }
           if (moveRIGHT==1) { moveRIGHT=0;  }
          }

HTML CODE 
<canvas id="myCanvas" width="480" height="960" onmouseup="touch_UP();"></canvas>


来源:https://stackoverflow.com/questions/2794769/manipulation-and-touch-events-not-firing-but-mouse-events-do

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!