touchstart

Determine touch position on tablets with JavaScript

梦想的初衷 提交于 2020-05-15 07:53:13
问题 I have an object with the name "element". If somebody touches the tablet, I would like to return the x and y coordinates of the touch position relative to the object, i. e. the upper left corner of the object has the coordinates x=0 and y=0. I know how to implement this on desktops: $(function() { $(document).mousedown(function(e) { var offset = $("#element").offset(); var relativeX = (e.pageX - offset.left); var relativeY = (e.pageY - offset.top); alert(relativeX+':'+relativeY); $(".position

Is it possible to simulate isTrusted=true

浪尽此生 提交于 2020-01-15 06:26:30
问题 I want to be able to simulate an isTrusted=true when I call a touchStart event. Is there any library or workaround of any sort to make this possible? Here is the output when I run the touchStart programmatically vs. when I actually call the touchStart. I am using mobile safari. According to this site mobile safari does not support it but that can't be true as the output shows the presence of the event. Any help/advice on this would be greatly appreciated. Thank you. 回答1: Not possible. Events

Is it possible to simulate isTrusted=true

柔情痞子 提交于 2020-01-15 06:26:06
问题 I want to be able to simulate an isTrusted=true when I call a touchStart event. Is there any library or workaround of any sort to make this possible? Here is the output when I run the touchStart programmatically vs. when I actually call the touchStart. I am using mobile safari. According to this site mobile safari does not support it but that can't be true as the output shows the presence of the event. Any help/advice on this would be greatly appreciated. Thank you. 回答1: Not possible. Events

How can I catch touchmove events on an element that is added to the DOM after my finger is already on the screen?

半城伤御伤魂 提交于 2020-01-13 09:21:12
问题 I am working on a Javascript / html5 project for iPad. I need to be able to catch touchmove events on an element that does not get added to the DOM until after a touchstart event has fired (i.e. until after a person has put their finger on the screen.) I have tried simulating a touchstart event and firing it programatically... $( "#container" ).append( element ); element.on( "touchmove", doStuff ); var ev = $.Event( "touchstart" ); element.trigger( ev ); ...however this does not work. The

Touch Events “touchstart” returns incorrect position on Mobile Safari. Workarounds?

青春壹個敷衍的年華 提交于 2019-12-25 12:26:08
问题 I am developing an HTML5 Canvas project and while adding multitouch support for mobile devices, I seem to have run into an issue on Mobile Safari in iOS 7.1. The main way that users interact with my app is by clicking and dragging. On the desktop, I add the appropriate mouse event listeners to my canvas... c.addEventListener('mousedown', mouseDown, false); c.addEventListener('mousemove', mouseMoved, false); c.addEventListener('mouseup', mouseUp, false); ... have these event handlers calculate

jQuery touchmove not registering in chrome emulator

你离开我真会死。 提交于 2019-12-25 02:52:23
问题 There's been similar questions on how to fire scroll events (mid-scroll) on mobile/tablet. I've used the code provided below but I've yet to get this to work in chrome emulator. $('body').on({ 'touchmove': function(e) { console.log($(this).scrollTop()); // Replace this with your code. } }); touchstart will log when I scroll with the touch sensor but not touchmove. What am I missing? 回答1: Did you enable the "emulate touch screen"? check this link in "sensors" http://www.sitepoint.com/use

click and hold to scroll, touchstart, touchmove, touchend

你离开我真会死。 提交于 2019-12-22 00:34:59
问题 I have a scrollable div. I want people to be able to scroll the list through 'hold', and also select a button for click. The problem is that when a button is held in order to scroll the div, it is triggering the click function. I want that do not trigger when scrolling. I need some way to differentiate click of the hold function. So I'm using: $('.panel').bind("touchstart mousedown", function (e) { console.log(e.type); $(this).addClass('resize'); }).bind("touchmove mousemove", function (e) {

ng-touchstart and ng-touchend in Angularjs

让人想犯罪 __ 提交于 2019-12-18 18:52:20
问题 I have an element which fires functions on ng-mousedown and ng-mouseup . However, It doesn't work on touch screen, is there any directive like ng-touchstart and ng-touchend ? 回答1: There is a module for this: https://docs.angularjs.org/api/ngTouch But you can write your own directives for events too: <!doctype html> <html> <head> <script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.0/angular.js"></script> </head> <body ng-app="plunker"> <div ng-controller="MainCtrl"> <div my

How to replace click with touchstart on iOS devices

[亡魂溺海] 提交于 2019-12-17 18:56:51
问题 Objective To close the parent div of an anchor tag when clicked. In the code below, I want to hide div performance_tt when the user clicks on anchor tag close_performance_tt . Problem Unable to get it to work on iOS devices after spending several hours at it. Works fine on everything else, even a BlackBerry 10 device. <div id="performance_tt" style="display: none;width: 300px;height: 200;overflow: auto;padding: 5px;background-color: yellow;"> <div>Website performance has become an important

jQuery events on iOS 5

↘锁芯ラ 提交于 2019-12-06 01:55:30
问题 I'm having an issue with jQuery 1.6.4, iOS 5 and the registration of touchstart/touchend events (as stated in the title, obviously). Take the following code: <!DOCTYPE html> <html lang="fr"> <head> <meta charset="utf-8" /> <script type="text/javascript" src="mmpa/jquery-1.6.4.min.js"></script> <script type="text/javascript"> $(document).ready(function() { var $body = $('body'); $('<button>').html('test jQuery').bind('touchstart', function() { alert('touchstart'); }).appendTo($body); }); <