AngularSwiper在大小调整时宽度持续增加
创始人
2024-10-29 17:00:33
0
  1. 在swiper的初始化时设置observer: true,这样swiper将会需要做出相应的变化以适应新的容器大小。示例代码如下:

import { Swiper, SwiperOptions } from 'swiper'; const swiperOptions: SwiperOptions = { direction: 'horizontal', slidesPerView: 'auto', spaceBetween: 0, observer: true, }; const swiper = new Swiper('.swiper-container', swiperOptions);

  1. 对于Angular应用,可以使用ngAfterViewInit钩子在DOM重绘之后初始化Swiper,以便正确计算容器大小。示例代码如下:

import { AfterViewInit, Component, ElementRef } from '@angular/core'; import Swiper from 'swiper'; @Component({ selector: 'app-swiper', template:

{{ item }}
, }) export class SwiperComponent implements AfterViewInit { items = ['Slide 1', 'Slide 2', 'Slide 3']; constructor(private elementRef: ElementRef) {}

ngAfterViewInit(): void {
  const swiper = new Swiper(this.elementRef.nativeElement.querySelector('.swiper-container'), {
    direction: 'horizontal',
    slidesPerView: 'auto',
    spaceBetween: 0,
    observer: true,
  });
}

}

相关内容

热门资讯

程序员教你!超凡辅助app链接... 程序员教你!超凡辅助app链接(白金岛手游放炮罚有挂)切实有作弊器开挂辅助工具(有挂猫腻);白金岛手...
玩家必看教程!518互游辅助(... 【福星临门,好运相随】;玩家必看教程!518互游辅助(如何做方片十三张脚本)从前有作弊器开挂辅助黑科...
玩家必看教程!新海豚辅助工具(... 玩家必看教程!新海豚辅助工具(微友助手破解版)好像有作弊挂开挂辅助神器(有挂秘笈);1、让任何用户在...
分享一款!新众亿软件可以安装(... 分享一款!新众亿软件可以安装(福州十八扑外卦)一向有作弊挂开挂辅助下载(今日头条);分享一款!新众亿...
实测教程!新财神正版辅助挂(游... 实测教程!新财神正版辅助挂(游戏辅助器免费版)其实有作弊挂开挂辅助插件(有挂辅助);游戏辅助器免费版...
玩家必看!新九哥智能辅助软件(... 玩家必看!新九哥智能辅助软件(小程序能不能开挂)确实有作弊器开挂辅助神器(有挂技巧);新九哥智能辅助...
信息共享!火神工作室辅助大全(... 信息共享!火神工作室辅助大全(朋友圈辅助软件)果然有作弊挂开挂辅助神器(有挂工具);一、火神工作室辅...
玩家必看科普!樱花之盛免费挂(... 玩家必看科普!樱花之盛免费挂(边锋老友辅助)固有有作弊挂开挂辅助脚本(有挂秘籍);亲真的是有正版授权...
总算清楚!天天微友辅助神器(上... 总算清楚!天天微友辅助神器(上饶打炸辅助)最初有作弊器开挂辅助工具(确实有挂);天天微友辅助神器 a...
科技新动态!微友辅助神器下载(... 科技新动态!微友辅助神器下载(人海大厅脚本)最初有作弊挂开挂辅助神器(有挂头条);科技新动态!微友辅...