Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.javascript > #31382
| Path | csiph.com!eternal-september.org!feeder.eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail |
|---|---|
| From | Ben Bacarisse <ben.usenet@bsb.me.uk> |
| Newsgroups | comp.lang.javascript |
| Subject | Re: Differentiate between touch start and click |
| Date | Fri, 16 Sep 2016 11:25:15 +0100 |
| Organization | A noiseless patient Spider |
| Lines | 32 |
| Message-ID | <87eg4kkupg.fsf@bsb.me.uk> (permalink) |
| References | <I9SdnaAw9NE7MUbKnZ2dnUU7-VfNnZ2d@westnet.com.au> |
| Mime-Version | 1.0 |
| Content-Type | text/plain |
| Injection-Info | mx02.eternal-september.org; posting-host="017616aa25f81ec581c44d76d61ba2f3"; logging-data="9996"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1/QHffj5TTz3j35FdNcl23lFk6CZruGI1E=" |
| Cancel-Lock | sha1:mXquBRzYk/LY8e+O3ZRyK3vt0V4= sha1:BSPsnEBDdMULZw/jo8yhOBhcOeY= |
| X-BSB-Auth | 1.ea6da32aeb1d4d7b3d71.20160916112515BST.87eg4kkupg.fsf@bsb.me.uk |
| Xref | csiph.com comp.lang.javascript:31382 |
Show key headers only | View raw
Andrew Poulos <ap_prog@hotmail.com> writes:
> I have a touchstart event and a click event both triggering this function
>
> function checkTrigger(e){
> if (e.type != "click") {
> e = e.touches[0];
> }
>
> var elem = document.elementFromPoint(e.pageX - window.pageXOffset,
> e.pageY - window.pageYOffset);
> ...
> }
>
> To tell whether it was a touchstart or a click I'm using
> (e.type != "click")
> is that the right way to differentiate between the two or should I
> have two smaller functions (one for each event) which then pass on the
> relevant values to checkTrigger?
I don't think it matters much but I would, in general, make the test
positive (logically you are doing something when it's a touch event, not
when it isn't a click event). Indeed, you might even want to test for
the touches property itself.
I'd be more concerned about the pageX/pageY stuff which is not
standardised (though I may be behind the times on that). You usually
get the target element using "e.target" and "this" will usually refer to
the element to which the listener was added.
--
Ben.
Back to comp.lang.javascript | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
Differentiate between touch start and click Andrew Poulos <ap_prog@hotmail.com> - 2016-09-16 18:26 +1000
Re: Differentiate between touch start and click Ben Bacarisse <ben.usenet@bsb.me.uk> - 2016-09-16 11:25 +0100
Re: Differentiate between touch start and click Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2016-09-17 00:06 +0200
Re: Differentiate between touch start and click Andrew Poulos <ap_prog@hotmail.com> - 2016-09-18 19:25 +1000
csiph-web