在某些分辨率以下删除光滑滑块 /卡罗尔的麻烦

发布于 2025-02-12 19:02:28 字数 1285 浏览 1 评论 0原文

我很难删除低于一定分辨率(768px)的屏幕的光滑颂歌。这是我正在使用的代码(我在堆栈溢出上找到了它)。问题是,添加此代码后,我的光滑颂歌根本不会显示。

 $slickGreen = false;
    function greenSlider(){    
        if($(window).width() > 768){
            if(!$slickGreen){
                $('#book-carosel').slick({
            slidesToShow: 6,
        slidesToScroll: 1,
        autoplay: true,
        autoplaySpeed: 2000,
        arrows: true,
        infinite:true
       }).show();
   
                });
                $slickGreen = true;
            }
        } else if($(window).width() < 767){
            if($slickGreen){
                $('#book-carosel').slick('unslick');
                $slickGreen = false;
            }
        }
    };
 });

$(document).ready(function(){
        ....
        greenSlider();
    });
    $(window).on('resize', function(){
         ....
         greenSlider();
    });

我的原始代码确实可以显示颂歌,如下所示:

  $(document).ready(function(){
      $('#book-carosel').slick({
        slidesToShow: 6,
        slidesToScroll: 1,
        autoplay: true,
        autoplaySpeed: 2000,
        arrows: true,
        infinite:true
   
      }).show();
    });

任何帮助都将不胜感激。

I'm having trouble removing my slick carosel for screens below a certain resolution (768px). Here is the code I'm using (I found it here on Stack overflow). The trouble is, my slick carosel won't display at all after adding this code.

 $slickGreen = false;
    function greenSlider(){    
        if($(window).width() > 768){
            if(!$slickGreen){
                $('#book-carosel').slick({
            slidesToShow: 6,
        slidesToScroll: 1,
        autoplay: true,
        autoplaySpeed: 2000,
        arrows: true,
        infinite:true
       }).show();
   
                });
                $slickGreen = true;
            }
        } else if($(window).width() < 767){
            if($slickGreen){
                $('#book-carosel').slick('unslick');
                $slickGreen = false;
            }
        }
    };
 });

$(document).ready(function(){
        ....
        greenSlider();
    });
    $(window).on('resize', function(){
         ....
         greenSlider();
    });

My original code that does work to display the carosel is as follows:

  $(document).ready(function(){
      $('#book-carosel').slick({
        slidesToShow: 6,
        slidesToScroll: 1,
        autoplay: true,
        autoplaySpeed: 2000,
        arrows: true,
        infinite:true
   
      }).show();
    });

Any help would be much appreciated.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

一桥轻雨一伞开 2025-02-19 19:02:28

如果这对某人有帮助,我终于弄清楚了如何做到这一点。我使用的所有代码都在下面。注意:使用XML字符,因为我使用的是Blogger模板,该模板不允许'或&gt; &lt;标志。

   
$(document).ready(function() {
    // This will fire when document is ready:
    $(window).on('resize', function(){
        // This will fire each time the window is resized:
        if($(window).width() >= 1024) {
            // if larger or equal
        $('#book-carosel').slick({
        slidesToShow: 6,
        slidesToScroll: 1,
        autoplay: true,
        autoplaySpeed: 2000,
        arrows: true,
        infinite:true
   
      }).show();

             } else if ($(window).width() >= 800) {
            // if smaller
            $('#book-carosel').slick({
                slidesToShow: 4,
                slidesToScroll: 1,
                autoplay: true,
                autoplaySpeed: 2000,
               arrows: true,
               infinite:true
   
              }).show();
   
           } else if ($(window).width() >= 600) {
            // if smaller
            $('#book-carosel').slick({
                slidesToShow: 3,
                slidesToScroll: 1,
                autoplay: true,
                autoplaySpeed: 2000,
               arrows: true,
               infinite:true
   
              }).show();
   
        } else if ($(window).width() >= 300) {
            // if smaller
            $('#book-carosel').slick({
                slidesToShow: 2,
                slidesToScroll: 1,
                autoplay: true,
                autoplaySpeed: 2000,
               arrows: true,
               infinite:true
   
        
   
              }).show();
   
        } else {
  //  block of code to be executed if the condition1 is false and condition2 is false
            $('#book-carosel').unslick();
        }
    }).resize(); // This will simulate a resize to trigger the initial run.
});

In case this helps someone, I have finally figured out how to do this. All of the code I used is below. Note: XML characters were used since I am using a Blogger template, which doesn't allow ' or > < signs.

   
$(document).ready(function() {
    // This will fire when document is ready:
    $(window).on('resize', function(){
        // This will fire each time the window is resized:
        if($(window).width() >= 1024) {
            // if larger or equal
        $('#book-carosel').slick({
        slidesToShow: 6,
        slidesToScroll: 1,
        autoplay: true,
        autoplaySpeed: 2000,
        arrows: true,
        infinite:true
   
      }).show();

             } else if ($(window).width() >= 800) {
            // if smaller
            $('#book-carosel').slick({
                slidesToShow: 4,
                slidesToScroll: 1,
                autoplay: true,
                autoplaySpeed: 2000,
               arrows: true,
               infinite:true
   
              }).show();
   
           } else if ($(window).width() >= 600) {
            // if smaller
            $('#book-carosel').slick({
                slidesToShow: 3,
                slidesToScroll: 1,
                autoplay: true,
                autoplaySpeed: 2000,
               arrows: true,
               infinite:true
   
              }).show();
   
        } else if ($(window).width() >= 300) {
            // if smaller
            $('#book-carosel').slick({
                slidesToShow: 2,
                slidesToScroll: 1,
                autoplay: true,
                autoplaySpeed: 2000,
               arrows: true,
               infinite:true
   
        
   
              }).show();
   
        } else {
  //  block of code to be executed if the condition1 is false and condition2 is false
            $('#book-carosel').unslick();
        }
    }).resize(); // This will simulate a resize to trigger the initial run.
});
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文