Forums

The forums ran from 2008-2020 and are now closed and viewable here as an archive.

Home Forums JavaScript Triggering a wheel event on mobile

  • This topic is empty.
Viewing 7 posts - 1 through 7 (of 7 total)
  • Author
    Posts
  • #203884
    Shikkediel
    Participant

    Will mobile browsers know what this event is when it is triggered like this?

    $(window).trigger('mousewheel');
    

    Obviously it won’t be able to listen for the manual event when it has no mouse but from what I can find (not a lot) it should not be an unknown event to Safari. That would mean that if you trigger it (without a mouse), you’d still be able to do stuff with it.

    This real or am I just wacko to think so?

    #203916
    Shikkediel
    Participant

    I really think I need a (or any) mobile device to test stuff on…

    But from what I read on the Apple page, wheel events are part of the mobile API. And can even be triggered without a mouse :

    Apple doc link

    If the user holds two fingers down on a scrollable element and moves the fingers, mousewheel events are generated.

    Back to the mental drawing board…

    #203961
    Ilan Firsov
    Participant

    Short answer, yes.

    var triggers = 0;
    $(document).on('mousewheel', function(e) {
      $('.count').text(++triggers);
    });
    
    $(document).on('touchmove', function() { //touchmove works for iOS, I don't know if Android supports it
      $(document).trigger('mousewheel');
    });
    

    Tested it here on iPad/iPhone:
    http://codepen.io/ilanf/pen/mJBdgL/

    #203972
    Shikkediel
    Participant

    Neat, thanks for the feedback and making that demo. B-)

    That’ll give some interesting new use for the event. They should really trigger a wheel instead though to join the more common (modern) term. But it’s good stuff in any case.

    #253501
    Naveenraj
    Participant

    It is nice and helped me lot, but i had an issue, Is it possible to find touch move is happening in the direction of top to bottom or bottom to top??

    #253515
    Shikkediel
    Participant

    Have a look at the lower part of my answer here:

    http://stackoverflow.com/a/32652836/3168107

    #253518
    Ilan Firsov
    Participant

    There also this library which adds common gesture events. Give this a try
    http://hammerjs.github.io

Viewing 7 posts - 1 through 7 (of 7 total)
  • The forum ‘JavaScript’ is closed to new topics and replies.