如何仅将jquery应用于移动设备? [英] How do I apply jquery for mobile only?

查看:81
本文介绍了如何仅将jquery应用于移动设备?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我只需要将以下jquery应用于移动浏览器:

I need to apply the following jquery for mobile browsers only:

<script>
   $('.right').insertBefore('left');
</script>

这是为了重新排列引导程序列的位置.

This is to reorder the position of bootstrap columns.

我该怎么做?是否需要包裹在东西中?

How do I do this? Does it need to be wrapped in something?

推荐答案

总是很难检测它是移动设备的浏览器还是带触摸屏的笔记本电脑.因此,与其检测您是否担心屏幕尺寸,不如不建议您检测屏幕尺寸,并且如果屏幕尺寸低于一定水平(请说在481px以下),我们将假定它是移动屏幕并执行您的屏幕.所需的代码如下:

It always very hard to detect whether its a mobile device's browser or a laptop with a touch screen. So instead of detecting that if you are concern about the screen size then i will recommend you to detect the screen size and if its below certain level(lets say below 481px) then we will assume that its a mobile screen and will execute your needed code as follows:

$(document).ready(function () {
    $(window).on("resize", function (e) {
        checkScreenSize();
    });

    checkScreenSize();

    function checkScreenSize(){
        var newWindowWidth = $(window).width();
        if (newWindowWidth < 481) {
            $('.right').insertBefore('.left');
        }
        else
        {
            $('.left').insertBefore('.right');
        }
    }
});

这篇关于如何仅将jquery应用于移动设备?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆