微信小程序:视图容器
来源:互联网 发布:免费语音朗读软件 编辑:程序博客网 时间:2024/05/17 08:36
view
把文档分割为独立的、不同的部分。
示例:
<!--一个块级区域--><view style="background: pink; height: 200px;"> block </view><!--一个行级区域--><view style="display: inline-block; background: red;"> inline1 </view><!--一个行级区域--><view style="display: inline-block; backgrondd: blue;"> inline2 </view>
view可以使用弹性和模型进行布局,可以设置style
为:
style="display: flex; flex-direction: row/column; justify-content: center/flex-start/flex-end/space-between/space-around; align-items: center/flex-start/flex-end;"
scroll-view
可滚动试图区域
设置竖向滚动条位置scroll-leftNumber
设置横向滚动条位置scroll-into-viewString
值应为某子元素id,则滚动到该元素,元素顶部对齐滚动区域顶部bindscrolltoupperEventHandle
滚动到顶部/左边,会触发scrolltoupper事件bindscrolltolowerEventHandle
滚动到底部/右边,会触发scrolltolower事件bindscrollEventHandle
滚动时触发,event.detail总携带{scrollLeft,scrollTop,scrollHeight,scrollWidth,deltaX,deltaY}
使用竖向滚动条时要给scroll-view一个固定高度,拖更说wxss
设置height
。
示例:
<view class="section"> <view class="section__title">vertical scroll</view> <scroll-view scroll-y="true" style="height: 200px;" bindscrolltoupper="upper" bindscrolltolower="lower" bindscroll="scroll" scroll-into-view="{{toView}}" scroll-top="{{scrollTop}}"> <view id="green" class="scroll-view-item bc_green"></view> <view id="red" class="scroll-view-item bc_red"></view> <view id="yellow" class="scroll-view-item bc_yellow"></view> <view id="blue" class="scroll-view-item bc_blue"></view> </scroll-view> <view class="btn-area"> <button size="mini" bindtap="tap">click me to scroll into view </button> <button size="mini" bindtap="tapMove">click me to scroll</button> </view></view><view class="section section_gap"> <view class="section__title">horizontal scroll</view> <scroll-view class="scroll-view_H" scroll-x="true" style="width: 100%"> <view id="green" class="scroll-view-item_H bc_green"></view> <view id="red" class="scroll-view-item_H bc_red"></view> <view id="yellow" class="scroll-view-item_H bc_yellow"></view> <view id="blue" class="scroll-view-item_H bc_blue"></view> </scroll-view></view>
.js:
var order = ['red', 'yellow', 'green', 'blue', 'red']Page({ data: { toView: "red", scrollTop: 100 }, upper: function(e) { console.log(e) }, lower: function(e) { console.log(e) }, scroll: function(e) { console.log(e) }, tap: function(e) { for (var i = 0; i < order.length; ++i) { if (order[i] === this.data.toView) { this.setData({ toView: order[i + 1] }) break } } }, tapMove: function(e) { this.setData({ scrollTop: this.data.scrollTop + 10 }) }})
.wxss
.section { margin-bottom: 40px}.section_title { margin-bottom: 8px; padding-left: 15px; padding-right: 15px}.scroll-view-item { height: 200px;}.btn-area { width: 100%; height: 40px;}.section_gap { padding: 0 15px}.scection_gap .section_title { padding-left: 0; padding-right: 0}.scroll-view_H { white-space: nowrap}.scroll-view-item_H { display: inline-block; width: 100%; height: 200px}.bc_red { background: red;}.bc_green { background: green;}.bc_yellow { background: yellow;}.bc_blue { background: blue;}
效果图(ps:不知道怎么给这个开发工具模拟器录屏 -_-):
swiper
滑动面板
current改变时会触发change事件,event.detail={current:current}
注意:其中只可放置swiper-item组件,其他节点会被自动删除
swiper-item
仅可放置在swiper组件中,宽高自动设置为100%。
.wxml:
<swiper indicator-dots="{{indicatorDots}}" autoplay="{{autoplay}}" interval="{{interval}}" duration="{{duration}}"> <block wx:for-items="{{imgUrls}}"> <swiper-item> <image src="{{item}}" class="slide-image" width="355" height="150"/> </swiper-item> </block></swiper><button bindtap="changeIndicatorDots"> indicator-dots </button><button bindtap="changeAutoplay"> autoplay </button><slider bindchange="intervalChange" show-value min="500" max="2000"/> interval<slider bindchange="durationChange" show-value min="1000" max="10000"/> duration
.js:
Page({ data: { imgUrls: [ 'http://img02.tooopen.com/images/20150928/tooopen_sy_143912755726.jpg', 'http://img06.tooopen.com/images/20160818/tooopen_sy_175866434296.jpg', 'http://img06.tooopen.com/images/20160818/tooopen_sy_175833047715.jpg' ], indicatorDots: false, autoplay: false, interval: 5000, duration: 1000 }, changeIndicatorDots: function(e) { this.setData({ indicatorDots: !this.data.indicatorDots }) }, changeAutoplay: function(e) { this.setData({ autoplay: !this.data.autoplay }) }, intervalChange: function(e) { this.setData({ interval: e.detail.value }) }, durationChange: function(e) { this.setData({ duration: e.detail.value }) }
swiper和scroll-view的区别:
1,scroll-view是连续平滑的滚动,视图停留在滑动动作离开的位置,swiper是自带分页效果,视图在滑动动作离开后,继续滑动值当前页。
2,swiper具备指示点。
0 1
- 微信小程序:视图容器
- 微信小程序-view(视图容器)
- 3、微信小程序笔记---视图容器
- 【微信小程序】视图容器-view组件
- 【微信小程序】视图容器-scroll-view组件
- 【微信小程序】视图容器-swiper组件
- 微信小程序组件1--视图容器
- 微信小程序基础组件之视图容器
- 2.1.1微信小程序视图容器 view
- 微信小程序的视图容器-- scroll-view
- 微信小程序的视图容器—swiper
- 微信小程序的视图容器-view
- 微信小程序之滑块视图容器(swiper)
- 微信小程序开发手记之四:视图容器
- 2.1.3微信小程序滑块视图容器 swiper
- 微信小程序—swiper(滑块视图容器)
- 微信小程序--movable-view(可移动的视图容器)
- 小程序五:组件之视图容器
- maque
- js中的arguments的解析
- 一个iOS项目总结(二):界面
- HDU 4870 Rating
- 商城之Fresco(FaceBook)
- 微信小程序:视图容器
- 欧拉角的详解
- 在virtualenv虚拟环境下使用pip
- hdu1713相遇周期
- 用GitHub和Hexo搭建个人博客
- CCPC[长春] 6.Harmonic Value Description 规律+贪心
- linux入门练习题之权限
- implicit declaration of function-linux C文件编译warning解决方法
- Collections 对List排序