tencent cloud

文档反馈

视图容器

最后更新时间:2024-03-04 22:43:53

    scroll-view

    功能说明:可滚动视图区域。使用竖向滚动时,需要给<scroll-view>一个固定高度,通过 WXSS 设置 height。
    参数及说明:
    属性
    类型
    默认值
    说明
    scroll-x
    boolean
    false
    允许横向滚动
    scroll-y
    boolean
    false
    允许纵向滚动
    upper-threshold
    number/string
    50
    距顶部/左边多远时,触发 scrolltoupper
    lower-threshold
    number/tring
    50
    距底部/右边多远时,触发 scrolltolower 事件
    scroll-top
    number/string
    -
    设置竖向滚动条位置
    scroll-left
    number/string
    -
    设置横向滚动条位置
    scroll-into-view
    string
    -
    值应为某子元素 id(id 不能以数字开头)。设置哪个方向可滚动,则在哪个方向滚动到该元素
    scroll-with-animation
    boolean
    false
    在设置滚动条位置时使用动画过渡
    enable-back-to-top
    boolean
    false
    iOS 单击顶部状态栏、Android 双击标题栏时,滚动条返回顶部,只支持竖向
    bindscrolltoupper
    eventhandle
    -
    滚动到顶部/左边时触发
    bindscrolltolower
    eventhandle
    -
    滚动到底部/右边时触发
    bindscroll
    eventhandle
    -
    滚动时触发,event.detail = {scrollLeft, scrollTop, scrollHeight, scrollWidth, deltaX, deltaY}
    aria-label
    string
    false
    -
    enhanced
    boolean
    true
    -
    bounces
    boolean
    true
    -
    show-scrollbar
    boolean
    false
    -
    paging-enabled  
    boolean
    false
    -
    fast-deceleration
    boolean
    false
    -
    示例代码:
    对应的 WXML 文件
    <view class="section">
    <view class="section__title">vertical scroll</view>
    <view class="section__title">纵向滚动</view>
    <scroll-view
    scroll-y
    style="height: 200px;"
    bindscrolltoupper="upper"
    bindscrolltolower="lower"
    bindscroll="scroll"
    scroll-into-view="{{toView}}"
    scroll-top="{{scrollTop}}"
    >
    <view id="green" class="scroll-view-item bc_cyanblue">A</view>
    <view id="red" class="scroll-view-item bc_blue">B</view>
    </scroll-view>
    </view>
    <view class="section section_gap">
    <view class="section__title">horizontal scroll</view>
    <view class="section__title">横向滚动</view>
    <scroll-view class="scroll-view_H" scroll-x style="width: 100%">
    <view id="green" class="scroll-view-item_H bc_cyanblue"></view>
    <view id="red" class="scroll-view-item_H bc_blue"></view>
    </scroll-view>
    </view>
    对应的 js 文件
    const order = ['red', 'yellow', 'blue', 'green', 'red']
    Page({
    data: {
    toView: 'red',
    scrollTop: 100
    },
    upper(e) {
    console.log(e)
    },
    lower(e) {
    console.log(e)
    },
    scroll(e) {
    console.log(e)
    },
    tap(e) {
    for (let i = 0; i < order.length; ++i) {
    if (order[i] === this.data.toView) {
    this.setData({
    toView: order[i + 1]
    })
    break
    }
    }
    },
    tapMove(e) {
    this.setData({
    scrollTop: this.data.scrollTop + 10
    })
    }
    })
    
    
    
    说明:
    请勿在 scroll-view 中使用 textarea、map、canvas、video 组件。
    scroll-into-view 的优先级高于 scroll-top。
    在滚动 scroll-view 时会阻止页面回弹,所以在 scroll-view 中滚动,是无法触发 onPullDownRefresh。
    若要使用下拉刷新,请使用页面的滚动,而不是 scroll-view ,这样也能通过点击顶部状态栏回到页面顶部。

    swiper

    功能说明:滑块视图容器。change事件返回detail中包含一个source字段,表示导致变更的原因,可能值如下:
    autoplay自动播放导致 swiper 变化;
    touch用户滑动引起 swiper 变化;
    其他原因将用空字符串表示。
    注意:
    其中只可放置<swiper-item/>组件,否则会导致未定义的行为。
    参数及说明:
    属性
    类型
    默认值
    说明
    indicator-dots
    boolean
    false
    是否显示面板指示点
    indicator-color
    color
    rgba(0, 0, 0, .3)
    指示点颜色
    indicator-active-color
    color
    #000000
    当前选中的指示点颜色
    autoplay
    coolean
    false
    是否自动切换
    current
    number
    0
    当前所在滑块的 index
    interval
    number
    5000
    自动切换时间间隔
    duration
    number
    500
    滑动动画时长
    circular
    boolean
    false
    是否采用衔接滑动
    vertical
    boolean
    false
    滑动方向是否为纵向
    previous-margin
    string
    "0px"
    前边距,可用于露出前一项的一小部分,接受 px 和 rpx 值
    next-margin
    string
    "0px"
    后边距,可用于露出后一项的一小部分,接受 px 和 rpx 值
    display-multiple-items
    number
    1
    同时显示的滑块数量
    skip-hidden-item-layout
    boolean
    false
    是否跳过未显示的滑块布局,设为 true 可优化复杂情况下的滑动性能,但会丢失隐藏状态滑块的布局信息
    bindchange
    eventhandle
    -
    current 改变时会触发 change 事件,event.detail = {current: current, source: source}
    bindtransition
    eventhandle
    -
    swiper-item 的位置发生改变时会触发 transition 事件,event.detail = {dx: dx, dy: dy}
    bindanimationfinish
    eventhandle
    -
    动画结束时会触发 animationfinish 事件,event.detail 同上

    swiper-item

    功能说明:仅可放置在<swiper>组件中,宽高自动设置为100%。
    参数及说明:
    属性名
    类型
    默认值
    说明
    item-id
    string
    “”
    该 swiper-item 的标识符
    示例代码:
    对应的 WXML 文件
    <swiper
    indicator-dots="{{indicatorDots}}"
    autoplay="{{autoplay}}"
    interval="{{interval}}"
    duration="{{duration}}"
    >
    <block wx.for="{{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: [
    'https://img02.tooopen.com/images/20150928/tooopen_sy_143912755726.jpg',
    'https://img06.tooopen.com/images/20160818/tooopen_sy_175866434296.jpg',
    'https://img06.tooopen.com/images/20160818/tooopen_sy_175833047715.jpg'
    ],
    indicatorDots: false,
    autoplay: false,
    interval: 5000,
    duration: 1000
    },
    changeIndicatorDots(e) {
    this.setData({
    indicatorDots: !this.data.indicatorDots
    })
    },
    changeAutoplay(e) {
    this.setData({
    autoplay: !this.data.autoplay
    })
    },
    intervalChange(e) {
    this.setData({
    interval: e.detail.value
    })
    },
    durationChange(e) {
    this.setData({
    duration: e.detail.value
    })
    }
    })

    view

    功能描述:视图容器。
    参数及说明:
    属性名
    类型
    默认值
    说明
    hover-class
    string
    none
    指定按下去的样式类。当hover-class="none"时,没有点击态效果
    hover-stop-propagation
    boolean
    false
    指定是否阻止本节点的祖先节点出现点击态
    hover-start-time
    number
    50
    按住后多久出现点击态,单位毫秒
    hover-start-time
    number
    400
    手指松开后点击态保留时间,单位毫秒
    aria-role
    string
    -
    无障碍访问,(角色)标识元素的作用
    aria-label
    string
    -
    无障碍访问,(属性)元素的额外描述
    示例代码:
    对应的 WXML 文件
    <view class="section">
    <view class="section__title">flex-direction: row</view>
    <view class="flex-wrp" style="flex-direction:row;">
    <view class="flex-item bc_cyanblue">A</view>
    <view class="flex-item bc_blue">B</view>
    <view class="flex-item bc_grey">C</view>
    </view>
    </view>
    <view class="section">
    <view class="section__title">flex-direction: column</view>
    <view class="flex-wrp" style="height: 300px;flex-direction:column;">
    <view class="flex-item bc_cyanblue">A</view>
    <view class="flex-item bc_blue">B</view>
    <view class="flex-item bc_grey">C</view>
    </view>
    </view>
    
    
    
    说明:
    如果需要使用滚动视图,请使用 scroll-view

    movable-area

    功能说明:movable-view 的可移动区域。
    参数及说明:
    属性名
    类型
    默认值
    说明
    scale-area
    boolean
    false
    当里面的 movable-view 设置为支持双指缩放时,设置此值可将缩放手势生效区域修改为整个movable-area。
    注意:
    当 movable-view 小于 movable-area 时,movable-view 的移动范围是在 movable-area 内。
    当 movable-view 大于 movable-area 时,movable-view 的移动范围必须包含 movable-area(x 轴方向和 y 轴方向分开考虑)。
    示例代码:
    对应的 WXML 文件
    <view class="section">
    <view class="section__title">movable-view区域小于movable-area</view>
    <movable-area style="height: 200px; width: 200px; background: red;">
    <movable-view
    style="height: 50px; width: 50px; background: blue;"
    x="{{x}}"
    y="{{y}}"
    direction="all"
    ></movable-view>
    </movable-area>
    <view class="btn-area">
    <button size="mini" bindtap="tap">click me to move to (30px, 30px)</button>
    </view>
    <view class="section__title">movable-view区域大于movable-area</view>
    <movable-area style="height: 100px; width: 100px; background: red;">
    <movable-view
    style="height: 200px; width: 200px; background: blue;"
    direction="all"
    ></movable-view>
    </movable-area>
    <view class="section__title">可放缩</view>
    <movable-area
    style="height: 200px; width: 200px; background: red;"
    scale-area
    >
    <movable-view
    style="height: 50px; width: 50px; background: blue;"
    direction="all"
    bindchange="onChange"
    bindscale="onScale"
    scale
    scale-min="0.5"
    scale-max="4"
    scale-value="2"
    ></movable-view>
    </movable-area>
    </view>
    对应的 js 文件
    Page({
    data: {
    x: 0,
    y: 0
    },
    tap(e) {
    this.setData({
    x: 30,
    y: 30
    })
    },
    onChange(e) {
    console.log(e.detail)
    },
    onScale(e) {
    console.log(e.detail)
    }
    })

    movable-view

    功能说明:可移动的视图容器,在页面中可以拖拽滑动。
    参数及说明:
    属性名
    类型
    默认值
    说明
    direction
    string
    none
    movable-view 的移动方向,属性值有 all、vertical、horizontal、none
    inertia
    boolean
    false
    movable-view 是否带有惯性
    out-of-bounds
    boolean
    false
    超过可移动区域后,movable-view 是否还可以移动
    x
    number / string
    -
    定义 x 轴方向的偏移,如果 x 的值不在可移动范围内,会自动移动到可移动范围;改变 x 的值会触发动画
    y
    number / string
    -
    定义 y 轴方向的偏移,如果 y 的值不在可移动范围内,会自动移动到可移动范围;改变 y 的值会触发动画
    damping
    number
    20
    阻尼系数,用于控制 x 或 y 改变时的动画和过界回弹的动画,值越大移动越快
    friction
    number
    2
    摩擦系数,用于控制惯性滑动的动画,值越大摩擦力越大,滑动越快停止;必须大于0,否则会被设置成默认值
    disabled
    boolean
    false
    是否禁用
    scale
    boolean
    false
    是否支持双指缩放,默认缩放手势生效区域是在 movable-view 内
    scale-min
    number
    0.5
    定义缩放倍数最小值
    scale-max
    number
    10
    定义缩放倍数最大值
    scale-value
    number
    1
    定义缩放倍数,取值范围为0.5 - 10
    animation
    boolean
    true
    定义缩放倍数,取值范围为0.5 - 10
    bindchange
    eventhandle
    -
    拖动过程中触发的事件,event.detail = {x: x, y: y, source: source},其中 source 表示产生移动的原因,值可为 touch(拖动)、touch-out-of-bounds(超出移动范围)、out-of-bounds(超出移动范围后的回弹)、friction(惯性)和空字符串(setData)
    bindscale
    eventhandle
    -
    缩放过程中触发的事件,event.detail = {x: x, y: y, scale: scale}
    除了基本事件外,movable-view 提供了两个特殊事件。
    类型
    触发条件
    htouchmove
    初次手指触摸后移动为横向的移动,如果 catch 此事件,则意味着 touchmove 事件也被 catch
    vtouchmove
    初次手指触摸后移动为纵向的移动,如果 catch 此事件,则意味着 touchmove 事件也被 catch
    说明:
    movable-view 必须设置 width 和 height 属性,不设置默认为10px。
    movable-view 默认为绝对定位,top 和 left 属性为0px。
    movable-view 必须在 <movable-area/> 组件中,并且必须是直接子节点,否则不能移动。

    cover-image

    功能说明:覆盖在原生组件之上的图片视图,可覆盖的原生组件同 cover-view,支持嵌套在 cover-view 里。
    参数及说明:
    属性名
    类型
    默认值
    说明
    src
    string
    -
    图标路径,支持临时路径、网络地址、云文件 ID。暂不支持 base64 格式
    bindload
    eventhandle
    -
    图片加载失败时触发
    binderror
    eventhandle
    -
    图片加载失败时触发
    aria-role
    string
    -
    无障碍访问,(角色)标识元素的作用
    aria-lable
    string
    -
    无障碍访问,(角色)标识元素的作用
    说明:
    <cover-view> 和 <cover-image> 的 aria-role 仅可设置为 button,读屏模式下才可以单击,并朗读出“按钮”;为空时可以聚焦,但不可单击。
    事件模型遵循冒泡模型,但不会冒泡到原生组件。
    文本建议都套上 cover-view 标签,避免排版错误。
    只支持基本的定位、布局、文本样式。不支持设置单边的 border、background-image、shadow、overflow: visible 等。
    建议子节点不要溢出父节点。
    默认设置的样式有:white-space: nowrap; line-height: 1.2; display: block。
    自定义组件嵌套 cover-view 时,自定义组件的 slot 及其父节点暂不支持通过 wx:if 控制显隐,否则会导致 cover-view 不显示。
    示例代码:
    对应的 WXML 文件
    <video
    id="myVideo"
    src="https://qzonestyle.gtimg.cn/qzone/qzact/act/external/qq-video/qq-video.mp4"
    controls="{{false}}"
    event-model="bubble"
    >
    <cover-view class="controls">
    <cover-view class="play" bindtap="play">
    <cover-image class="img" src="/path/to/icon_play" />
    </cover-view>
    <cover-view class="pause" bindtap="pause">
    <cover-image class="img" src="/path/to/icon_pause" />
    </cover-view>
    <cover-view class="time">00:00</cover-view>
    </cover-view>
    </video>
    对应的 WXSS 文件
    .controls {
    position: relative;
    top: 50%;
    height: 50px;
    margin-top: -25px;
    display: flex;
    }
    .play,
    .pause,
    .time {
    flex: 1;
    height: 100%;
    }
    .time {
    text-align: center;
    background-color: rgba(0, 0, 0, 0.5);
    color: white;
    line-height: 50px;
    }
    .img {
    width: 40px;
    height: 40px;
    margin: 5px auto;
    }
    对应的 js 文件
    Page({
    onReady() {
    this.videoCtx = wx.createVideoContext('myVideo')
    },
    play() {
    this.videoCtx.play()
    },
    pause() {
    this.videoCtx.pause()
    }
    })

    cover-view

    功能说明:覆盖在原生组件之上的文本视图,可覆盖的原生组件包括mapvideocanvascameralive-playerlive-pusher,只支持嵌套cover-viewcover-image,可在cover-view中使用button
    参数及说明:
    属性名
    类型
    默认值
    说明
    scroll-top
    number / string
    -
    设置顶部滚动偏移量,仅在设置了 overflow-y: scroll 成为滚动元素后生效
    aria-role
    string
    -
    无障碍访问,(角色)标识元素的作用
    aria-label
    string
    -
    无障碍访问,(属性)元素的额外描述
    
    联系我们

    联系我们,为您的业务提供专属服务。

    技术支持

    如果你想寻求进一步的帮助,通过工单与我们进行联络。我们提供7x24的工单服务。

    7x24 电话支持