首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >几个斯威伯滑块在同一角度的应用程序/组件?

几个斯威伯滑块在同一角度的应用程序/组件?
EN

Stack Overflow用户
提问于 2020-05-07 07:44:01
回答 1查看 1.4K关注 0票数 1

我使用刷卡添加滑块到我的角度(7)应用程序。

问题是,即使不是在同一个组件中,我也无法在同一应用程序上有单独的滑块。

Swiper doc告诉我们,当您将它与vanilla JS一起使用时:

代码语言:javascript
复制
var mySwiper = new Swiper('.swiper-container', {
  speed: 400,
  spaceBetween: 100
});

在我的角应用程序中,我在.ts文件中有这样的内容:

代码语言:javascript
复制
import { Component, OnInit, Input } from '@angular/core';
import { ProductItemVM } from 'src/app/models/product/product-item-vm';
import { SwiperConfigInterface } from 'ngx-swiper-wrapper';

@Component({
  selector: 'srp-product-carousel-container',
  templateUrl: './product-carousel-container.component.html',
  styleUrls: ['./product-carousel-container.component.scss']
})

export class ProductCarouselContainerComponent implements OnInit {
@Input() productList: ProductItemVM[];

public config: SwiperConfigInterface = {
direction: 'horizontal',
threshold: 0,
spaceBetween: 20,
slidesPerView: 1,
keyboard: true,
mousewheel: false,
scrollbar: false,
navigation: true,
pagination: true
};

constructor() { }

ngOnInit() {}
}

这是Swiper角度包装的doc

我不能声明一个新的滑块,所以我不能调用另一个滑动容器类来瞄准不同的滑块。

有没有人有过这个问题,并找到了解决它的方法?谢谢。

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2020-11-09 17:12:28

我们可以使用ngx-swiper-wrapper在同一个页面或组件上使用多个滑块。

如果我们想增加两个卡索/滑块-一个用于推荐信,另一个用于图库,那么我们需要创建两个单独的托拉斯。

代码语言:javascript
复制
    import { SwiperConfigInterface } from 'ngx-swiper-wrapper';
    
    @Component({
      selector: 'app-home',
      templateUrl: './home.component.html',
      styleUrls: ['./home.component.scss']
    })

    export class HomeComponent implements OnInit {
    
      constructor() { }
    
      ngOnInit(): void {
      }

      gallery_config: SwiperConfigInterface = {
            direction: 'horizontal',
            slidesPerView: 1,
            allowTouchMove: true,
            pagination:{el:'.swiper-pagination',clickable:true},
            autoplay: {
              delay: 3000,
              disableOnInteraction: true
            }
      };
        
      testimonial_config: SwiperConfigInterface = {
            direction: 'horizontal',
            slidesPerView: 3,
            spaceBetween: 40,
            allowTouchMove: true,
            scrollbar:true
      };

现在将配置添加到相应的刷容器中。

将gallery_config添加到一个刷卡容器中

代码语言:javascript
复制
<div  class="swiper-container" [swiper]="gallery_config" >
        <div class="swiper-wrapper">
          <div  class="swiper-slide">
             ...
          </div>
        </div>
        <div class="swiper-pagination"></div>
</div>

将testimonial_config添加到另一个刷容器中

代码语言:javascript
复制
 <div  class="swiper-container" [swiper]="testimonial_config" >
            <div class="swiper-wrapper">
              <div  class="swiper-slide">
                 ...
              </div>
            </div>
            <div class="swiper-pagination"></div>
    </div>

如果你有更多的刷容器,那么你可以用不同的名称创建更多的配置,如果每个配置都有不同的滑动样式,那么就分配给它们。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/61652399

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档