jquery - 调整屏幕大小时尝试使用 flickity

标签 jquery html css

以下 jquery 代码是我用来在屏幕尺寸减小时为我的 div 应用 flickity slider 的代码!但这不起作用...请告诉我这段代码有什么问题:

(function($) {
    $(window).resize(function resize(){
        if ($window.width() < 700) {
            $(".container").addClass('gallery').addClass('js-flickity');
            $(".article").addClass('gallery-cell');
        }

        $(".container").removeClass('gallery').removeClass('js-flickity');
        $(".article").removeClass('gallery-cell');
    }).trigger('resize');
})(jQuery);

在这里,container 是包装 div(class:article) 的类。以下是 gallery 和 gallery-cell 的 CSS:

.gallery {
    background: #EEE;
}

.gallery-cell {
    width: 100%;
    height: 200px;
    margin-right: 10px;
    background: #8C8;
    counter-increment: gallery-cell;
}

/* cell number */
.gallery-cell:before {
    display: block;
    text-align: center;
    content: counter(gallery-cell);
    line-height: 200px;
    font-size: 80px;
    color: white;
}

请让我知道代码的问题。谢谢

最佳答案

检查一下你应该使用默认的 Flickity 选项。

http://codepen.io/desandro/pen/xVBpqG

//在 768px 处启用上一个/下一个按钮

if ( matchMedia('screen and (min-width: 768px)').matches ) {
  options.prevNextButtons = true;
}

关于jquery - 调整屏幕大小时尝试使用 flickity,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36679173/

相关文章:

html - 如何更改 html/css 中 &lt;header&gt; 部分的高度?

javascript - 如何限制 Bootstrap 日历插件中的日期范围?

javascript - VM[number] 文件导致未捕获的语法错误 : Unexpected identifier

html - CSS 置顶,然后滚动回到顶部

html - 悬停在图像上时数据悬停不显示

javascript - 如何居中一个绝对位置的div?

jquery - 内部链接滚动不起作用

jquery - 如何使用jquery将图像添加到div的顶部

javascript - 在 &lt;input&gt; 或 &lt;textarea&gt; 中选择文本后的 HTML 工具提示

html - 可变宽度父 div 内的绝对位置