Disable jQuery for mobile devices

前端 未结 3 1532
执念已碎
执念已碎 2020-12-22 13:32

I would like to disable part of my jQuery script for mobile devices, heres the code I\'d like to disable:

$(\'#inner-slide1\').click(function(e) {
    e.prev         


        
相关标签:
3条回答
  • 2020-12-22 13:46

    You may try

    MatchMedia.js

    There is details on https://github.com/paulirish/matchMedia.js

    You can load the plugins according to the certain viewport size.

    0 讨论(0)
  • 2020-12-22 13:55

    Using the code from http://detectmobilebrowsers.com/ use the JS code to detect if mobile - very comprehensive detection... will require a bit of modification as their function will redirect... but should be easy to do :)

    Also here is another good answer from here: disable script for mobiles

    0 讨论(0)
  • 2020-12-22 13:57

    You're repeating a function 5 times when you need only do it once if you just give those elements a class (I'm going for .inner-slide):

    var isMobile = /Android|webOS|iPhone|iPad|iPod|BlackBerry/i.test(navigator.userAgent) ? true : false;
    
    $('.inner-slide').click(function(e) {
        if(!isMobile) {
            e.preventDefault();
            dataslide = $(this).attr('data-slide');
            goToByScroll(dataslide);
        }
    });
    

    The if statement will only result to true on a mobile device (Android,webOS,iPhone,iPad,iPod,Blackberry)

    And please note that

    $(this).attr('data-slide');
    

    Can also be written as:

    $(this).data('slide');
    
    0 讨论(0)
提交回复
热议问题