Slick Carousel保持垂直,不具有响应性/点击?

huangapple go评论66阅读模式
英文:

Slick Carousel with stays vertical and is not responsive/clicking?

问题

以下是您提供的内容的翻译:

所以,我接了一个项目,其中已经有一个漂亮的走马灯,对Drupal或Bootstrap不太熟悉,但从我所看到的文档来看,当前的跟随文档操作。走马灯是在断点上触发的(如在断点上确认的那样,走马灯箭头会出现在断点上),但走马灯不是水平的,箭头不起作用。请提供建议。

**app.js**
```javascript
explore: function explore() {
  $('.explore-carousel').slick({
    autoplay: true,
    mobileFirst: true,
    infinite: false,
    dots: false,
    slidesToShow: 2,
    slidesToScroll: 1,
    prevArrow: $('.explore-prev'),
    nextArrow: $('.explore-next'),
    responsive: [{
      breakpoint: 500,
      settings: {
        slidesToShow: 1
      }
    }]
  });
},
exploreResize: function exploreResize(carousel) {
  // https://github.com/kenwheeler/slick/issues/3282
  $(window).on('load resize orientationchange', function () {
    $(carousel).each(function () {
      var $carousel = $(this);
      if ($(window).width() > 768) {
        if ($carousel.hasClass('slick-initialized')) {
          $carousel.slick('unslick');
        }
      } else {
        if (!$carousel.hasClass('slick-initialized')) {
          CB.carousel.explore(carousel);
        }
      }
    });
  });
},

explore.twig

<section class="explore">
  <a class="explore-prev"><img src="../lib/img/icon-carousel-arrow-left.svg"></a>
  <a class="explore-next"><img src="../lib/img/icon-carousel-arrow-right.svg"></a>

  <div class="explore-carousel grid-x grid-container align-center">
    {% for block in entry.exploreMatrix.all() %}
    {% set image = block.icon.one() %}
    {% set link = block.linkUrl.one() %}
    {% set length = loop.length %}
    {% set col = 12/length %}

    <div class="cell small-12 large-{{ col ? col : 4 }}">
      <a class="explore--link" href={{ link.url }}>
        <div class="outline">
          <img class="explore-image" src="{{ image ? image.url : '' }}">
          <div class="hover--container">
            <div class="hr"></div>
            <h3 class="hover--text">{{ block.linkText }}<span class="button-icon">{% include 'includes/svg/cta-arrow' %}</span></h3>
          </div>
        </div>
      </a>
    </div>
    {% endfor %}
  </div>
</section>

css

.explore {
  margin-top: 80px;
  @include mq($small) {
    margin-top: 0;
  }
  position: relative;
  .explore-prev {
    @extend .PrevArrow;
  }
  .explore-next {
    @extend .NextArrow;
  }
  .explore-carousel {
    display: flex;
    @include h-padding(rem-calc(50));
    // padding-left: rem-calc(50);
    // padding-right: rem-calc(50);

    @include mq($medium) {
      // padding-left: initial;
      // padding-right: initial;
      @include h-padding(initial);
    }
    .explore--link {
      width: 100%;
    }

    .outline {
      position: relative;
      width: rem-calc(250);
      border-radius: 50%;
      transition: all .3s;
      margin: 0 auto;
      @include spacer(50px, 50px);
      &.hover {
        background: $offWhite;
      }
      @include mq($medium) {
        width: rem-calc(300);
      }

      .hover--container {
        transition: all .3s;
        position: absolute;
        left: 0;
        right: 0;
        margin: 0 auto;
        bottom: 5%;
        text-align: center;
        opacity: 0;
        .hover--text {
          margin-top: rem-calc(10);
          font-size: rem-calc(22);
          color: $clay;
          letter-spacing: -1px;
        }
      }
      .explore--image {
        width: rem-calc(250);
        margin: 0 auto;
        @include mq($medium) {
          width: rem-calc(300);
        }
      }
    }
    .hover {
      .hover--container {
        transition: all .3s;
        opacity: 1;
      }
    }
  }
}

希望这有助于您理解代码和问题。如果需要进一步的帮助,请告诉我。

英文:

So, I have a project that I've taken on that already has a slick carousel, not familiar with drupal or bootstrap, but from what I can see the current follows documentation. The carousel is triggered upon the breakpoint (as confirmed by the carousel arrows that appear at the breakpoint), However the carousel is not horizontal and the arrows do not work. Please advise.

app.js

explore: function explore() {
$(&#39;.explore-carousel&#39;).slick({
autoplay:true,
mobileFirst:true,
infinite: false,
dots: false,
slidesToShow: 2,
slidesToScroll: 1,
prevArrow: $(&#39;.explore-prev&#39;),
nextArrow: $(&#39;.explore-next&#39;),
responsive: [{
breakpoint: 500,
settings: {
slidesToShow: 1
}
}]
});
},
exploreResize: function exploreResize(carousel) {
// https://github.com/kenwheeler/slick/issues/3282
$(window).on(&#39;load resize orientationchange&#39;, function () {
$(carousel).each(function () {
var $carousel = $(this);
if ($(window).width() &gt; 768) {
if ($carousel.hasClass(&#39;slick-initialized&#39;)) {
$carousel.slick(&#39;unslick&#39;);
}
} else {
if (!$carousel.hasClass(&#39;slick-initialized&#39;)) {
CB.carousel.explore(carousel);
}
}
});
});
},

explore.twig

&lt;section class=&quot;explore&quot;&gt;
&lt;a class=&quot;explore-prev&quot;&gt;&lt;img src=&quot;../lib/img/icon-carousel-arrow-left.svg&quot;&gt;&lt;/a&gt;
&lt;a class=&quot;explore-next&quot;&gt;&lt;img src=&quot;../lib/img/icon-carousel-arrow-right.svg&quot;&gt;&lt;/a&gt;
&lt;div class=&quot;explore-carousel grid-x grid-container align-center&quot;&gt;
{% for block in entry.exploreMatrix.all() %}
{% set image = block.icon.one() %}
{% set link = block.linkUrl.one() %}
{% set length = loop.length %}
{% set col = 12/length %}
&lt;div class=&quot;cell small-12 large-{{ col ? col : 4 }}&quot;&gt;
&lt;a class=&quot;explore--link&quot; href={{ link.url }}&gt;
&lt;div class=&quot;outline&quot;&gt;
&lt;img class=&quot;explore-image&quot; src=&quot;{{ image ? image.url : &#39;&#39; }}&quot;&gt;
&lt;div class=&quot;hover--container&quot;&gt;
&lt;div class=&quot;hr&quot;&gt;&lt;/div&gt;
&lt;h3 class=&quot;hover--text&quot;&gt;{{ block.linkText }}&lt;span class=&quot;button-icon&quot;&gt; {% include &#39;includes/svg/cta-arrow&#39; %}&lt;/span&gt;&lt;/h3&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;/a&gt;
&lt;/div&gt;
{% endfor %}
&lt;/section&gt;

css

.explore {
margin-top: 80px;
@include mq($small) {
margin-top: 0;
}
position: relative;
.explore-prev {
@extend .PrevArrow;
}
.explore-next {
@extend .NextArrow;
}
.explore-carousel {
display: flex;
@include h-padding(rem-calc(50));
// padding-left: rem-calc(50);
// padding-right: rem-calc(50);
@include mq($medium) {
// padding-left: initial;
// padding-right: initial;
@include h-padding(initial);
}
.explore--link {
width: 100%;
}
.outline {
position: relative;
width: rem-calc(250);
border-radius:50%;
transition: all .3s;
margin: 0 auto;
@include spacer(50px, 50px);
&amp;.hover {
background: $offWhite;
}
@include mq($medium) {
width: rem-calc(300);
}
.hover--container {
transition: all .3s;
position: absolute;
left: 0;
right: 0;
margin: 0 auto;
bottom: 5%;
text-align: center;
opacity: 0;
.hover--text {
margin-top:rem-calc(10);
font-size: rem-calc(22);
color: $clay;
letter-spacing: -1px;
}
}
.explore--image {
width: rem-calc(250);
margin: 0 auto;
@include mq($medium) {
width: rem-calc(300);
}
}
}
.hover {
.hover--container {
transition: all .3s;
opacity: 1;
}
}
}
}

答案1

得分: 1

关于'不水平'问题我不太确定,但我建议您删除所有CSS并在沙箱中运行slick轮播。完成后,添加您的CSS代码。

使用slick时,CSS覆盖可能会很麻烦。

关于箭头,我猜您需要将其注册为字符串HTML标记。像这样:

prevArrow: '

我的自定义上一个箭头

'

英文:

Not sure about the 'not horizontal' issue, but i recommend you to remove all css and run slick carousel in a sandbox. When done, add your CSS code.

CSS overrides can be painfull with slick.

About the arrows, i guess you need to register as string HTML markup. Like this:

prevArrow:&#39;&lt;div&gt; my custom prev arrow &lt;/div&gt;&#39;

huangapple
  • 本文由 发表于 2020年1月7日 02:18:12
  • 转载请务必保留本文链接:https://go.coder-hub.com/59616998.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定