Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>@SamuelRossille No browsers that I'm aware of expose the existence of (or lack thereof) a mouse, unfortunately.</p> <p>So, with that being said, we just have to try and do the best we can with our existing option... events. I know it's not exactly what you're looking for... agreed it is currently far from ideal.</p> <p>We can do our best to figure out whether a user is using a mouse or touch at any given moment. Here is a quick and dirty example using jQuery &amp; Knockout:</p> <pre><code>//namespace window.ns = {}; // for starters, we'll briefly assume if touch exists, they are using it - default behavior ns.usingTouch = ko.observable(Modernizr.touch); //using Modernizr here for brevity. Substitute any touch detection method you desire // now, let's sort out the mouse ns.usingMouse = ko.computed(function () { //touch if (ns.usingTouch()) { //first, kill the base mousemove event //I really wish browsers would stop trying to handle this within touch events in the first place window.document.body.addEventListener('mousemove', function (e) { e.preventDefault(); e.stopImmediatePropagation(); }, true); //remove mouse class from body $('body').removeClass("mouse"); //switch off touch listener $(document).off(".ns-touch"); // switch on a mouse listener $(document).on('mousemove.ns-mouse', function (e) { if (Math.abs(window.lastX - e.clientX) &gt; 0 || window.lastY !== e.clientY) { ns.usingTouch(false); //this will trigger re-evaluation of ns.usingMouse() and result in ns.usingMouse() === true } }); return false; } //mouse else { //add mouse class to body for styling $('body').addClass("mouse"); //switch off mouse listener $(document).off(".ns-mouse"); //switch on a touch listener $(document).on('touchstart.ns-touch', function () { ns.usingTouch(true) }); return true; } }); //tests: //ns.usingMouse() //$('body').hasClass('mouse'); </code></pre> <hr> <p>You can now <strong>bind/subscribe to usingMouse()</strong> &amp; <strong>usingTouch()</strong> and/or style your interface with the <strong>body.mouse</strong> class. The interface will switch back and forth as soon as a mouse cursor is detected and on touchstart.</p> <p>Hopefully we'll have some better options from the browser vendors soon.</p>
    singulars
    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.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      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