javascript
onPageScroll((e) => {
// e.scrollTop基数为120,-30表示到30开始变色,/70表示到100比例就达到1.0。((100-30)/70)
let scale = (e.scrollTop - 30) / 70;
// let num = parseInt(255 - scale * 255 + "");
// num = num > 255 ? 255 : num;
// 背景透明度:0-100
alpha.value = scale > 1 ? 1 : scale;
if (scale < 1) {
color.value = "#ffffff";
uni.setNavigationBarColor({
frontColor: "#ffffff",
backgroundColor: "#ffffff"
});
} else {
color.value = "#000000";
uni.setNavigationBarColor({
frontColor: "#000000",
backgroundColor: "#ffffff"
});
}
});