Note that there are some explanatory texts on larger screens.

plurals
  1. POempty event listener: Is this ok?
    primarykey
    data
    text
    <p><strong>Some Quick Background</strong></p> <p>I'm building an iOS app that uses html web views in some areas. I wanted to make sure the html buttons on those pages looked and felt as much like iOS buttons as possible. To accomplish this, I wanted a tap state so the html button depressed when tapped. Now in HTML this is easy. You just set a style for :active or :hover or whatever. I actually had this defined already. In iOS, however, those states don't engage on tap – at least normally. So my goal was to write a little script that added a class to the button to change its appearance ontouchstart.</p> <p><strong>The Issue</strong></p> <p>However, it turns out I didn't need to get that complicated...by pure accident I ran a test with the following code:</p> <pre><code>document.addEventListener('touchstart', function(event) { console.log("test"); }, true); </code></pre> <p>I'm pretty green with javascript &amp; jQuery, so all I intended on doing was checking my syntax and making sure the eventListener fired when I tapped the button. To my surprise, the button's :active states in the css fired (as well as the :hover states). That code...solved my problem!</p> <p><strong>My Question</strong></p> <p>So here's my question: Is the above code valid? I mean, is it bad to do this? It's as if the empty eventListener just triggered behavior that desktop browsers already offer. Is there anything wrong with using this method? I'm green, but I don't want to pick up bad habits. If this is a bad way to code I don't want to use it.</p> <p>Thanks for any insight you guys can give me into this!</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload