view是微信小程序的最基本容器,作用与前端开发中的div容器作用相同,用于存放内容(默认垂直排列)。
view具有的属性
hover-class
类型:String
默认值:none
指定按下去的样式类。当 hover-class=“none” 时,没有点击态效果
示例代码:
<view class="title" hover-class="hClass">这是标题</view>
.title{ background:blue; }
/*普通样式*/
.hClass{ background:red; color:white; }
/*当按下view时背景色 改为red,文字颜色改为white*/
hover-start-time
类型:number
默认值:50(单位毫秒)
按住后多久出现点击态(hover-class的样式)
hover-stay-time
类型:number
默认值:200(单位毫秒)
手指松开后点击态保留时间
(hover-start-time和hover-stay-time属性在实际开发中应用较少)
示例代码:
<view class="title" hover-class="hClass"
hover-start-time="75" hover-stay-time>
这是标题</view>
<!--按下view容器75ms后显示hover-class样式,手指松开后保持200ms-->
.title{ background:blue; }
/*普通样式*/
.hClass{ background:red; color:white; }
/*当按下view时背景色 改为red,文字颜色改为white*/
hover-stop-propagation
类型:boolean
默认值:false
指定是否阻止本节点的祖先节点出现点击态
<view class="v1" hover-class="hV1">
<view class="v2" hover-class="hV2" hover-stop-propagation></view>
</view>
<!--二级容器,v2是v1的子容器,添加 hover-stop-propagation属性使得点击子容器的时候父容器不被影响-->
<!--点击v2时,v2的背景色改为 blueviolet,v1的背景色仍为 yellowgreen。-->
.v1{
width: 200px; height: 200px;
background: yellowgreen;
}
.hV1{
background: tomato;
}
.v2{
width: 100px; height: 100px;
background: blue;
}
.hV2{
background: blueviolet;
}
参考API网址:小程序API–view