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



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

eventAfterRender: function(event, element, view) {
    $(element).css('height','10px');
}
您可以将

$(window).width()用作

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

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

对于jquery中较小的屏幕,您可以使用以下命令定义窗口的大小

$(window).width()

并制定 if 条件

var windowWidth = $(window).width();
if(windowWidth<768){//Your script if device width is under 768px}

最新更新