【问题标题】:Swiperjs navigation arrows inside the slider滑块内的 Swiperjs 导航箭头
【发布时间】:2021-06-04 17:01:29
【问题描述】:

我有一个用 Angular 实现的 swiperjs 滑块。在其他情况下,您可以将导航代码放在 swiper 的容器元素之外。然而,在 Angular 中,情况有些不同。我尝试使用 CSS,但这没有帮助。它只是移出视线并开始从外面裁剪。

HTML 代码:

<swiper [class.d-none]="!(showRecommendations$ | async)"
    [slidesPerView]="2"
    [spaceBetween]="10"
    [navigation]="true"
    [breakpoints]="{
        '992': {
          slidesPerView: 3,
          spaceBetween: 10
        }
      }"
>
     <ng-template swiperSlide 
    *ngFor="let gift of (gifts$ | async); let i = index">...
    </ng-template>

</swiper>

TS 代码:

import SwiperCore, { Navigation } from "swiper/core";

...

SwiperCore.use([Navigation])

【问题讨论】:

    标签: html angular typescript swiperjs swiper.js


    【解决方案1】:
    <div style="position:relative;">
      <swiper [class.d-none]="!(showRecommendations$ | async)"
          [slidesPerView]="2"
          [spaceBetween]="10"
          navigation="navigation:  {
            nextEl: '.swiper-button-next',
            prevEl: '.swiper-button-prev',
          }"
          [breakpoints]="{
              '992': {
                slidesPerView: 3,
                spaceBetween: 10
              }
            }"
      >
          <ng-template swiperSlide 
          *ngFor="let gift of (gifts$ | async); let i = index">...
          </ng-template>
      </swiper>
      <div class="swiper-button-prev"></div>
      <div class="swiper-button-next"></div>
    <div>
    

    确保像我在答案中所做的那样为包装元素设置相对位置

    【讨论】:

    • 感谢您的回答。刚试了一下,但是显示错误“Error: Error: Quotes are not supported for evaluation! Statement: { nextEl: '.swiper-button-next', prevEl: '.swiper-button-prev' }”。有什么想法吗?
    • @Sarmad 我忘了删除 [navigation] 周围的括号,答案已修复
    • 还是不行。没有引号的导航指令不是 swiper js 组件的选项。
    猜你喜欢
    • 1970-01-01
    • 2013-02-20
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-03-28
    • 2011-12-03
    • 2022-01-16
    相关资源
    最近更新 更多