可滚动视图区域,用于区域滚动。使用竖向滚动时,需要给 scroll-view 一个固定高度,通过 css 设置 height;使用横向滚动时,需要给 scroll-view 添加 white-space: nowrap; 样式。
可滚动视图区域。使用竖向滚动时,需要给scroll-view一个固定高度,通过 WXSS 设置 height。组件属性的长度单位默认为px,2.4.0起支持传入单位(rpx/px)。
一般页面布局中某个模块需要局部滚动,以横向滚动更多,纵向滚动其实也类似。这个也是 scroll-view 最简单的用法,纵向滚动直接设置一个已知的固定高度 height 就行了,没啥难度。
常见整个页面布局,需要中间部分直接自适应屏幕然后局部滚动。这个实现稍微难一点:
// 获取屏幕可用高度
let screenHeight=uni.getSystemInfoSync().windowHeight
<template>
<div class="page">
<div class="top" />
<div class="center">
<scroll-view style="height: 100%;"></scroll-view>
</div>
<div class="bottom" />
</div>
<template>
<style>
.page {
display: flex;
flex-direction: column;
}
.top {
height: 100px;
background: green;
}
.bottom {
height: 100px;
background: red;
}
.center {
flex: 1;
}
</style>
这个就有点难度了,其实就是我们 pc 上常用的设置最大高度 max-height,如果超过了最大高度则出现滚动条,很不幸在小程序这种方式滚动不了。
一般用在弹窗中比较多,设置一个固定高度确实可以实现,但是内容较少时会出现大量留白,用纯 css 我是没找到实现方式,因为需要动态获取到内容的高度才知道要给 scroll-view 设置多高。
<template>
<div class="pop">
<div class="header">我是标题</div>
<scroll-view :style="'height:' + height + 'px'">
<div id="scroll-content"></div>
</scroll-view>
<div class="footer">确定</div>
</div>
<template>
<script>
export default {
data() {
return {
height: 200 // 默认滚动高度
}
},
mounted() {
// 实际弹窗中应该是在弹窗显示时去计算高度,此处仅作示例,获取不到节点信息可以放到 $nextTick 中去获取
this.calcHeight()
},
methods: {
calcHeight() {
const query=uni.createSelectorQuery().in(this)
query.select('#scroll-content').boundingClientRect(res=> {
const h=res ? res.height : 0
let height=this.height
if (h > 0 && h <=this.height) {
// 感觉获取到的 res.height 和实际的有大约 39px 误差,所以自己减去一点
height=(h > 19) ? (h - 19) : h
}
this.height=height
}).exec()
}
}
}
</script>
注意 createSelectorQuery 在自定义组件中要加上 in(this)
天给大家带来的内容是一款非常时尚的纯CSS3炫酷手机APP滑动菜单动画特效。
当鼠标移动到手机界面上的时候,菜单中的小图标会逐个滑动显示出来。而当鼠标移动到菜单区域会出现一个非常酷的半圆形扩展动画,同时菜单文字将逐一展现出来。
具体效果如下图:
HTML结构部分:手机界面滑动菜单动画特效的主要部分是菜单图标和菜单项的展示。这里使用一个嵌套<div>结构,菜单项中有超链接<a>元素来制作。
CSS样式部分:
开始的时候,菜单使用 right:﹣10px;隐藏起来。
当鼠标滑过的时候在将这个菜单列表再移回到屏幕当中。
每个菜单项都要通过nth﹣child旋转器来选择然后添加延迟时间。
至于半透明的遮罩层则使用social元素的:after伪元素来制作。
当鼠标滑过屏幕上方的header元素时将移动它的left属性,制作最后的效果。
今天的内容就分享到这里,更多内容敬请期待!
*请认真填写需求信息,我们会在24小时内与您取得联系。