V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
Johnsen
V2EX  ›  程序员

一款移动端微型 swiper 插件,小而美,无依赖.

  •  
  •   Johnsen · 2017-09-11 09:04:52 +08:00 · 2026 次点击
    这是一个创建于 2412 天前的主题,其中的信息可能已经有所发展或是发生改变。

    mSwiper.js · downloads license

    View README in English

    项目地址

    移动端微型 swiper 插件,小而美,无依赖.

    前言

    mSwiper 相对于其他的 swiper 插件而言,最大的优势就是 ,压缩后仅 1.2k ,能满足部分开发需求。插件的开发采用 组合使用构造函数模式和原型模式,通过 Gulp 构建,感兴趣的可以阅读源码🦄。欢迎 star 🌟

    若有问题,请提 issue

    效果演示

    在线浏览 Demo 请戳这里

    手机浏览请扫描下方二维码

    在线浏览

    开发

    # 克隆本仓库
    git clone https://github.com/JohnsenZhou/mSwiper.js.git
    
    # 进入仓库目录
    cd mSwiper.js
    
    # 安装依赖
    npm install
    
    # 启动项目,本地浏览地址 => localhost:8080
    gulp
    
    # 打包压缩
    gulp build
    
    

    安装

    前往 release 下载所需版本。

    使用

    <ul id="selector">
      <li>
        <img src="./img/1.jpg">
      </li>
      <li>
        <img src="./img/2.jpg">
      </li>
      <li>
        <img src="./img/3.jpg">
      </li>
      <li>
        <img src="./img/4.jpg">
      </li>
      <li>
        <img src="./img/5.jpg">
      </li>
    </ul>
    <script src="../src/mSwiper.js"></script>
    <script>
      var options = {
        selector: "#selector",  // 节点选择
        isAutoPlay: true,       // 是否自动播放
        autoPlayTime: 3000,     // 设置自动播放时间
      }
      var mSwiper = new mSwiper(options);
    </script>
    

    mSwiper 同时也支持 AMD 规范,你可以通过 require.js 进行加载使用:

    require(['mSwiper'], function(mSwiper) {
      var options = {
        selector: "#selector",  // 节点选择
        isAutoPlay: true,       // 是否自动播放
        autoPlayTime: 3000,     // 设置自动播放时间
      }
      var mSwiper = new mSwiper(options);
    })
    

    Api

    new mSwiper(options)

    options 具体参数:

    | 参数 | 类型 | 默认值 | 功能描述 | | ------------- |:-------------:| -----:| -----:| | selector | string | #selector | 容器选择器 | | isAutoPlay | bool | false| 是否自动播放 | | isManual | bool | false | 是否支持手指滑动 | | autoPlayTime | number | 5000 | 自动播放间隔时间 | | goDirection | string | left | 自动播放方向(left&right) |

    License

    MIT License

    7anshuai
        1
    7anshuai  
       2017-09-11 10:18:42 +08:00
    转发到了 https://jsernews.com/news/130 (然而并没有人会来看😂)
    blanu
        2
    blanu  
       2017-09-11 13:34:38 +08:00 via iPhone
    感谢分享。能否去掉 3D 效果?文档上没看到
    Johnsen
        3
    Johnsen  
    OP
       2017-09-11 14:37:56 +08:00
    @blanu 这一版只做了 3d 效果,后续会把你提到的功能加上去
    jinzhe
        4
    jinzhe  
       2017-09-11 15:29:53 +08:00
    不支持手指跟随,然后手动滑动后连续跳动问题
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   1213 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 26ms · UTC 18:01 · PVG 02:01 · LAX 11:01 · JFK 14:01
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.