How to get original Event without jQuery on iPhone

For some reason I can't use jQuery.

This is my code:

document.addEventListener("touchstart", function(e) {
    e.preventDefault();

    var orig = e.originalEvent;

    var x = orig.changedTouches[0].pageX;
    var y = orig.changedTouches[0].pageY;

    //id("#draggable").css({top: y, left: x});
    id("draggable").style.left = x;
    id("draggable").style.top = y;

});

Using jQuery you can get originalEvent, but if you are not using it, how to get it?

thank

+3
source share
4 answers
var x = e.pageX;

If you have Safari on your desktop, open it in iPhone mode
Develop-> User Agent-> Mobile Safari...
And put a breakpoint inside your function, you can check the e object and all its properties.

0
source

jQuery, event listener, jQuery. originalEvent - Event, , , jQuery, , , , originalEvent jQuery . e , e.originalEvent , jQuery.

+11

. "" , . , "hovered" true, , false. , , onchange. , onchange, , .

Of course, this is a quick and dirty solution to give you an idea. It can be done better. Hope this helps :)

var hovered = false;

$('#button').mouseover(function(){
    hovered = true;   
}).mouseleave(function(){
    hovered = false;
});

$(function(){
    $('#button').bind("click",function(){
          alert("button click");
      });
$('#textbox').bind("change",function(){

    alert("text changed");
    if (hovered)
        $('#button').trigger('click');                
});

});​
+1
source

I think you are using changeTouches, which is a list of Touches for each contact point that contributed to the event . Multi-touch is an example of when this will happen. For touchstart, you can simply check the strokes, the contact list for each contact point touching the surface .

var origTarget = e.originalEvent.touches[0].target
var x = e.originalEvent.touches[0].pageX
var y = e.originalEvent.touches[0].pageY
0
source

Source: https://habr.com/ru/post/1767826/


All Articles