Simple way to identify iOS user agent in a jQuery if/then statement?

前端 未结 6 2161
心在旅途
心在旅途 2021-02-01 03:16

Exactly like it sounds..

Is there some magical and easy way to say:

    if (user agent is iOS) {
        if (browserRatio >=1.5) {
            $contai         


        
6条回答
  •  傲寒
    傲寒 (楼主)
    2021-02-01 03:53

    In order for this to work you are going to need to define browserWidth, but yes it will work. Here I targeted iPad only.

        $(window).load(function(){
          var browserWidth = $(window).width(); 
    
          if (navigator.userAgent.match(/(iPad)/)) {
            if (browserWidth == 768) {
                $('.sectionI').css({'margin-left': '30px'});
            } else if (browserWidth == 1024)  {
                $('.sectionI').css({'margin-left': '0px'});
            }
          }
        });
    

提交回复
热议问题