仅将jquery代码应用于移动设备

Jul*_*anJ 2 jquery

我在网站上使用fullcalendar ,并且希望在较小的屏幕尺寸上稍微不同地设置事件样式。如果窗口低于特定大小,如何触发下面的代码?

eventAfterRender: function(event, element, view) {
    $(element).css('height','10px');
}
Run Code Online (Sandbox Code Playgroud)

Ank*_*wal 6

您可以$(window).width()用作

    var width = $(window).width();
    if (width <= 480) {
      //code for mobile devices
    } else {
      //code for other devices
    }
Run Code Online (Sandbox Code Playgroud)

$(window).width()为您提供设备的宽度(以像素为单位),您可以使用该值来相应地确定mobiletabletdesktop设备,并相应地添加设备特定代码。