可滾動視圖區域,用于區域滾動。使用豎向滾動時,需要給 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滑動菜單動畫特效。
當鼠標移動到手機界面上的時候,菜單中的小圖標會逐個滑動顯示出來。而當鼠標移動到菜單區域會出現一個非??岬陌雸A形擴展動畫,同時菜單文字將逐一展現出來。
具體效果如下圖:
HTML結構部分:手機界面滑動菜單動畫特效的主要部分是菜單圖標和菜單項的展示。這里使用一個嵌套<div>結構,菜單項中有超鏈接<a>元素來制作。
CSS樣式部分:
開始的時候,菜單使用 right:﹣10px;隱藏起來。
當鼠標滑過的時候在將這個菜單列表再移回到屏幕當中。
每個菜單項都要通過nth﹣child旋轉器來選擇然后添加延遲時間。
至于半透明的遮罩層則使用social元素的:after偽元素來制作。
當鼠標滑過屏幕上方的header元素時將移動它的left屬性,制作最后的效果。
今天的內容就分享到這里,更多內容敬請期待!
*請認真填寫需求信息,我們會在24小時內與您取得聯系。