Tiny-Swiper 稳定版发布啦 2kb 兼容 SwiperJS 的移动端轮播库 - V2EX
V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
爱意满满的作品展示区。
WeRDyin
V2EX    分享创造

Tiny-Swiper 稳定版发布啦 2kb 兼容 SwiperJS 的移动端轮播库

  •  
  •   WeRDyin 2019-12-09 20:14:46 +08:00 3051 次点击
    这是一个创建于 2216 天前的主题,其中的信息可能已经有所发展或是发生改变。

    介绍

    SwiperJS 是一个功能丰富的轮播库,且有着优秀的交互效果。但是它的 minimum 版本文件达到了 140kb,采用 gzip 压缩后也有 35kb,如果使用 ES module 版本,我们也需要调整构建配置或者 Polyfill。当未使用构建工具时,我们不得不引入整个 SwiperJS。并且,在大多数情况下,mobile 端的轮播效果都可以用其核心功能实现且不需要引入额外插件。

    当你也和我一样有上述需求时,Tiny-Swiper 或许是更好的选择

    • 核心库压缩后仅 2kb
    • 兼容 SwiperJS API
    • 良好的滑动体验
    • 插件支持
    • 测试用例覆盖

    如何使用

    完整文档

    查看详细文档及插件列表请点击这里 https://github.com/joe223/tiny-swiper

    基本用法

    来看一个示例:

    import Swiper from 'tiny-swiper' const swiper = new Swiper('#swiper') 

    就这样,你甚至可以只需更改 import 语句就能将 SwiperJS 替换为 Tiny-Swiper。

    引入插件

    我们再试试使用图片懒加载插件:

    import Swiper from 'tiny-swiper' import SwiperPluginLazyload from 'tiny-swiper/lib/modules/lazyload.min.js' Swiper.use([ SwiperPluginLazyload ]) const mySwiper = new Swiper('#swiper', { lazyload: { loadPrevNext: false, loadPrevNextAmount: 1, loadOnTransitionStart: false, elementClass: 'swiper-lazy', loadingClass: 'swiper-lazy-loading', loadedClass: 'swiper-lazy-loaded', preloaderClass: 'swiper-lazy-preloader' } }) 

    你也可以这么使用,只对单个实例生效:

    import Swiper from 'tiny-swiper' import SwiperPluginLazyload from 'tiny-swiper/lib/modules/lazyload.min.js' const mySwiper = new Swiper('#swiper', { Plugins: [ SwiperPluginLazyload ], lazyload: { loadPrevNext: false, loadPrevNextAmount: 1, loadOnTransitionStart: false, elementClass: 'swiper-lazy', loadingClass: 'swiper-lazy-loading', loadedClass: 'swiper-lazy-loaded', preloaderClass: 'swiper-lazy-preloader' } }) 

    以下是示例效果,更多示例请前往此处 https://joe223.com/tiny-swiper

    哈哈,稳定版的公告先发到 V 站,欢迎提 issue 交流想法。BTW,预祝 V2EX 社区的各位新年快乐!

    目前尚无回复
    关于     帮助文档     自助推广系统     博客     API     FAQ     Solana     779 人在线   最高记录 6679       Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 22ms UTC 20:12 PVG 04:12 LAX 12:12 JFK 15:12
    Do have faith in what you're doing.
    ubao msn snddm index pchome yahoo rakuten mypaper meadowduck bidyahoo youbao zxmzxm asda bnvcg cvbfg dfscv mmhjk xxddc yybgb zznbn ccubao uaitu acv GXCV ET GDG YH FG BCVB FJFH CBRE CBC GDG ET54 WRWR RWER WREW WRWER RWER SDG EW SF DSFSF fbbs ubao fhd dfg ewr dg df ewwr ewwr et ruyut utut dfg fgd gdfgt etg dfgt dfgd ert4 gd fgg wr 235 wer3 we vsdf sdf gdf ert xcv sdf rwer hfd dfg cvb rwf afb dfh jgh bmn lgh rty gfds cxv xcv xcs vdas fdf fgd cv sdf tert sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf shasha9178 shasha9178 shasha9178 shasha9178 shasha9178 liflif2 liflif2 liflif2 liflif2 liflif2 liblib3 liblib3 liblib3 liblib3 liblib3 zhazha444 zhazha444 zhazha444 zhazha444 zhazha444 dende5 dende denden denden2 denden21 fenfen9 fenf619 fen619 fenfe9 fe619 sdf sdf sdf sdf sdf zhazh90 zhazh0 zhaa50 zha90 zh590 zho zhoz zhozh zhozho zhozho2 lislis lls95 lili95 lils5 liss9 sdf0ty987 sdft876 sdft9876 sdf09876 sd0t9876 sdf0ty98 sdf0976 sdf0ty986 sdf0ty96 sdf0t76 sdf0876 df0ty98 sf0t876 sd0ty76 sdy76 sdf76 sdf0t76 sdf0ty9 sdf0ty98 sdf0ty987 sdf0ty98 sdf6676 sdf876 sd876 sd876 sdf6 sdf6 sdf9876 sdf0t sdf06 sdf0ty9776 sdf0ty9776 sdf0ty76 sdf8876 sdf0t sd6 sdf06 s688876 sd688 sdf86