支付宝小程序组件 视图容器·view

2020-09-18 10:47 更新

视图容器。相当于 web 的 div 或者 react-native 的 view。如果需要使用滚动视图,请使用 scroll-view。不支持 view 组件覆盖 map 组件,可通过同层渲染实现 cover-view 覆盖 map 组件

扫码体验

示例代码

  1. <!-- API-DEMO page/component/view.axml -->
  2. <view class="page">
  3. <view>
  4. <button a:if="{{returnIndex}}" onTap="returnIndex">回到首页</button>
  5. </view>
  6. <view class="page-description">视图容器,相当于 web 的 div 或者 react-native 的 View。</view>
  7. <view class="page-section">
  8. <view class="page-section-demo">
  9. <view class="stream">
  10. <view class="post">
  11. <view class="postUser">
  12. <view class="postUser__name">Chris</view>
  13. </view>
  14. <view class="postBody">
  15. <view class="postBody__content">
  16. 欢迎使用支付宝小程序!!!
  17. </view>
  18. <view class="postBody__date">
  19. May 20
  20. </view>
  21. </view>
  22. </view>
  23. <view class="post">
  24. <view class="postUser">
  25. <view class="postUser__name">Jack</view>
  26. </view>
  27. <view class="postBody">
  28. <view class="postBody__content">
  29. @Chris 我该如何上手?
  30. </view>
  31. <view class="postBody__date">
  32. May 21
  33. </view>
  34. </view>
  35. </view>
  36. <view class="post">
  37. <view class="postUser">
  38. <view class="postUser__name">Chris</view>
  39. </view>
  40. <view class="postBody">
  41. <view class="postBody__content">
  42. 你可以查看 Demo,对小程序有一个简单的了解;然后下载我们的 IDE 进行开发。
  43. </view>
  44. <view class="postBody__date">
  45. May 22
  46. </view>
  47. </view>
  48. </view>
  49. <view class="post">
  50. <view class="postUser">
  51. <view class="postUser__name">Jessie</view>
  52. </view>
  53. <!-- hover red -->
  54. <view class="postBody" hover-class="red">
  55. <view class="postBody__content">
  56. 赞!
  57. </view>
  58. <view class="postBody__date" hidden>
  59. June 1
  60. </view>
  61. </view>
  62. </view>
  63. <view class="post" hidden>
  64. <view class="postUser">
  65. <view class="postUser__name">Jessie</view>
  66. </view>
  67. <view class="postBody">
  68. <view class="postBody__content">
  69. 赞! +1
  70. </view>
  71. <view class="postBody__date">
  72. June 1
  73. </view>
  74. </view>
  75. </view>
  76. </view>
  77. </view>
  78. </view>
  79. </view>
  80. // API-DEMO page/component/view.js
  81. Page({
  82. data: {
  83. pageName: 'component/view',
  84. },
  85. onLoad() {
  86. this.setData({
  87. returnIndex: getCurrentPages().length === 1,
  88. })
  89. },
  90. returnIndex() {
  91. my.switchTab({ url: '/page/component/index' });
  92. },
  93. });
  94. /* API-DEMO page/component/view.acss */
  95. .post + .post {
  96. margin-top: 10rpx;
  97. }
  98. .post {
  99. display: flex;
  100. }
  101. .postUser {
  102. flex: 0 1 auto;
  103. padding-bottom: 20rpx;
  104. }
  105. .postUser__name {
  106. width: 180rpx;
  107. color: #57727C;
  108. font-size: 24rpx;
  109. font-weight: 700;
  110. line-height: 1;
  111. text-align: center;
  112. margin-top: 60rpx;
  113. }
  114. .postBody {
  115. flex: 1 1 0%;
  116. position: relative;
  117. padding: 30rpx;
  118. border: 2rpx solid #CAD0D2;
  119. border-radius: 8rpx;
  120. }
  121. .postBody:after,
  122. .postBody:before {
  123. right: 100%;
  124. top: 70rpx;
  125. border: solid transparent;
  126. content: " ";
  127. height: 0;
  128. width: 0;
  129. position: absolute;
  130. pointer-events: none;
  131. }
  132. .postBody:after {
  133. border-color: transparent;
  134. border-right-color: #ffffff;
  135. border-width: 16rpx;
  136. margin-top: -16rpx;
  137. }
  138. .postBody:before {
  139. border-color: transparent;
  140. border-right-color: #CAD0D2;
  141. border-width: 18rpx;
  142. margin-top: -18rpx;
  143. }
  144. .postBody__content {
  145. color: #57727C;
  146. font-size: 24rpx;
  147. }
  148. .postBody__date {
  149. margin-top: 10rpx;
  150. color: #86969C;
  151. font-size: 20rpx;
  152. text-transform: uppercase;
  153. letter-spacing: 2rpx;
  154. }

属性

属性名 类型 默认值 描述 最低版本
disable-scroll Boolean false 是否阻止区域内滚动页面。说明:如果 view 中嵌套 view,外层 view 设置 disable-scroll 为 true 时禁止内部的滚动。 -
hover-class String - 触摸时添加的样式类。 -
hover-start-time Number - 按住多久后出现点击状态,单位毫秒。 -
hover-stay-time Number - 松开后点击状态保留时间,单位毫秒。 -
hidden Boolean false 是否隐藏。 -
class String - 自定义样式名。 -
style String - 内联样式。 -
animation Object {} 用于动画,详见 my.createAnimation。使用 my.createAnimation 生成的动画是通过过渡(Transition)实现的,只会触发 onTransitionEnd,不会触发 onAnimationStartonAnimationIterationonAnimationEnd -
hover-stop-propagation Boolean false 是否阻止当前元素的祖先元素出现点击态。 1.10.0
onTap EventHandle - 点击。 -
onTouchStart EventHandle - 触摸动作开始。 -
onTouchMove EventHandle - 触摸后移动。 -
onTouchEnd EventHandle - 触摸动作结束。 -
onTouchCancel EventHandle - 触摸动作被打断,如来电提醒,弹窗。 -
onLongTap EventHandle - 长按 500ms 之后触发,触发了长按事件后进行移动将不会触发屏幕的滚动。 -
onTransitionEnd EventHandle - 过渡(Transition)结束时触发。 1.8.0
onAnimationIteration EventHandle - 每开启一次新的动画过程时触发。(第一次不触发) 1.8.0
onAnimationStart EventHandle - 动画开始时触发。 1.8.0
onAnimationEnd EventHandle - 动画结束时触发。 1.8.0
onAppear EventHandle - 当前元素可见面积超过50%时触发。 1.9.0
onDisappear EventHandle - 当前元素不可见面积超过50%时触发。 1.9.0
onFirstAppear EventHandle - 当前元素首次可见面积达到50%时触发。 1.9.4
role - - 表示组件的语义角色。设置为 img 时,组件聚焦后读屏软件会朗读出 图像 ;设置为 button 时,聚焦后读屏软件会朗读出 按钮 。详情请参见 aria-component -

常见问题

如何改变 view 的展示顺序?

将这两个模块嵌入到一个循环里面,每一个循环的小模块加一个类型值进行标识。

页面滚动时在不同屏幕滚动到的位置不同,如何解决?

  1. 按照屏幕的比例计算,换算跳转位置 。
  2. 固定一个滑动位置,在该位置写入一个 view,通过计算这个 view 到顶部距离,进行跳转。
以上内容是否对您有帮助:
在线笔记
App下载
App下载

扫描二维码

下载编程狮App

公众号
微信公众号

编程狮公众号