atom-design(Vue.js 移动端组件库)手势组件介绍和使用感受 - V2EX
V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
Reming960227
V2EX    前端开发

atom-design(Vue.js 移动端组件库)手势组件介绍和使用感受

  •  
  •   Reming960227 2019-05-17 12:05:29 +08:00 2374 次点击
    这是一个创建于 2343 天前的主题,其中的信息可能已经有所发展或是发生改变。

    介绍

    atom-design 经过几个月的开发,以及这段时间的修复 bug,对 js,css 压缩,按需引入处理等等的性能优化,现在已经逐渐完善.做这套 UI 考虑到很多性能的问题,以及如何让开发者更自由、更简单的去使用。您可以试着在生产环境中使用这篇文章主要讲使用 Gesture(手势)相关组件的介绍和使用感受。

    github 地址

    https://github.com/Reming960227/atom-design (可以点个 star 谢谢,给我们一点动力)

    中文文档

    https://atom-design.github.io/docs/#/

    Gesture(手势)相关组件

    • Carousel(传送带)
    • SlideItem (滑动条)
    • Range (区域选择)
    • Pull Gesture (上下拉动手势)

    Carousel(传送带)

    import {Carousel} from 'atom-design'; Vue.component(Carousel.name, Carousel); 
    <carousel> <div class="carousel-item item1">item1</div> <div class="carousel-item item2">item2</div> <div class="carousel-item item3">item3</div> </carousel> 

    使用 Carousel 来实现轮播图,每个一级子节点都会当成一个轮播滑块.传送带组件参考比较流行的 swiper 来设计,swiper.js 是通过自定义的复制副本个数,在头尾各自添加头部副本和尾部副本,滑动至最后一个和首个滑块的时候判断手势方向 translate 来切换到副本位置. 实现原理如下图:

    ( swiper.js 也是按此来实现的)

    效果如图:

    也可以在配置 Carousel pagination(Boolean):是否有分页 auto(Boolean):是否自动轮播 loop(Boolean):是否循环 time(Number):间隔多久轮播( auto 为 true 时生效) v-model(Number): 绑定轮播的序号(从 0 开始),也可以设置 v-model 的初始值来设置轮播从设置的序号开始轮播 
    <carousel :pagination="true" :auto="true" :loop="true" :time="5000" v-model="slideIdx"> <div class="carousel-item item1">item1</div> <div class="carousel-item item2">item2</div> <div class="carousel-item item3">item3</div> </carousel> 

    你会发现使用非常简单,而且轮播内容完全可以自己定制,不限制是图片,也可以是任何自定义 DOM

    SlideItem (滑动条)

    这是通过滑动来显示操作的组件

    import {SlideItem} from 'atom-design'; Vue.component(SlideItem .name, SlideItem); 
    <atom-slide v-model="isClose"> <div class="slide-action" slot="rightAction"> <div class="action edit" @click="show">编辑</div> <div class="action delete" @click="show">删除</div> </div> <div class="slide-demo">左右拖拽</div> <div class="slide-action" slot="leftAction"> <div class="action info" @click="show">查看</div> </div> </atom-slide> 

    效果如下图所示

    只需要通过 slot 来指定左右的操作菜单(可选值 leftAction/rightAction ),便能直接使用滑动功能. 如果你只需要左边或者右边的滑动菜单,则只设置一边即可,组件内部会自动限制另一边的滑动。内容无需通过 slot 命名,默认的未命名的插槽名都作为内容。

    v-model 绑定 slideItem 组件开关,v-model 指为 false 时,则 slideItem 会自动过渡到未滑动时的状态 

    Range (区域选择)

    import {Range} from 'atom-design'; Vue.component(Range.name, Range); 
    <atom-range v-model="range2" color="#dd2622"></atom-range> 

    效果如下所示:

    v-model 绑定滑动选择的数值,color 可以自定义主题颜色

    Pull Gesture (上拉下拉手势)

    此组件一般用来下拉来更新数据也可以通过上拉来做一些加载数据或者更新的操作 效果如下图所示:

    支持全局引入和按需引入

    全局引入

    import atomD from 'atom-design'; import 'atom-design/bundle/style.css'; Vue.use(atomD); 

    全局引入 atom-design 的 js 和 css 会全部引入到项目中,因此尽量选择按需引入

    按需引入

    按需引入步骤 使用 babel-plugin-component 插件来实现按需引入

    (1)先安装 babel-plugin-component npm install babel-plugin-component --save-dev (2)配置.babelrc [ "plugins": [ ["component", { "libraryName": "atom-design", "style": true }] ] ] (3)引入所需组件 import {Picker, Button} from 'atom-design'; Vue.component(Button.name, Button); const mOnthArr= [{ text: 1 }, { text: 2 }, { text: 3 }] Picker({ data: [{ text: 1996, childrens: monthArr }, { text: 1997, childrens: monthArr }, { text: 1998, childrens: monthArr }, { text: 1999, childrens: monthArr }, { text: 2000, childrens: monthArr }], submitBtn: { style: '', event: (res) => { // 选中的数据 console.log(res) } } }) 

    // 按需引入后打包完的 css 也只有使用到的 css 才会打包进入,几个组件仅仅只有 3kb // 按需引入后打包后的 js 也只有使用到的组件才会打包进去

    非常感谢您能够看到这里,这套 UI 现在已经趋于完善,你可以在生产环境中试着使用,如果有碰到问题可以在 github 地址提 issue, 我们会尽最快的时间去解决您遇到的问题。

    目前尚无回复
    关于     帮助文档     自助推广系统     博客     API     FAQ     Solana     5855 人在线   最高记录 6679       Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 27ms UTC 06:09 PVG 14:09 LAX 23:09 JFK 02:09
    Do have faith in wha you're doing.
    ubao 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