知識
不管是網站,軟件還是小程序,都要直接或間接能為您產生價值,我們在追求其視覺表現的同時,更側重于功能的便捷,營銷的便利,運營的高效,讓網站成為營銷工具,讓軟件能切實提升企業(yè)內部管理水平和效率。優(yōu)秀的程序為后期升級提供便捷的支持!
微信小程序 - IOS 仿餓了么"我的",下拉橡皮筋效果
發(fā)表時間:2021-3-31
發(fā)布人:葵宇科技
瀏覽次數:92
這個需求是在wepy交流群里有群友提到的. 一個小花樣.
注冊mixins
/**
* IOS專用 頂部下拉橡皮筋效果
* 安卓的Page在到達頂部的時候,不能繼續(xù)下拉...略過
*
* 效果見 餓了么送餐服務 "我的" 頁面 IOS環(huán)境 上下拖動
*
* 下拉時, 頂部色塊拉伸,上劃時,頂部色塊收縮.
* wxml :
<view style='background-color: #0000ff;min-height:50vh;z-index:-1;height:{{elastic_topHeight||50}}px;width:100%;position:fixed;top:{{elastic_top}}px;'></view>
*
*/
var obj = {
onLoad(){
/**獲取當前是何種平臺 */
var SystemInfo = getApp().globalData.SystemInfo||{};
this.__IS_IOS = SystemInfo.system && SystemInfo.system.toLowerCase().indexOf("ios")>=0;
},
onPageScroll(e) {
//非ios 略過效果
if (!this.__IS_IOS)return;
// console.log(e)
var top = e.scrollTop;
if (top > 0) { //上劃時, 整個view上移 , 避免因為持續(xù)上劃,看到 后面的view
this.setData({
elastic_top: -top
});
return;
}
this.setData({ //動態(tài)設置 高度
elastic_topHeight: Math.abs(top * 2)+50
});
}
};
module.exports= obj;
wxml很簡單.在你的最外層增加
<view style='background-color: #0000ff;min-height:50vh;z-index:-1;height:{{elastic_topHeight||50}}px;width:100%;position:fixed;top:{{elastic_top}}px;'></view>
style中顏色自定義,其他根據需要來
注意,他上拉的時候,背景色還是白色,和頂部顏色并不一樣.
這種方式實現,要求你的 頂級view要有一個背景色,否則這個橡皮筋效果就會暴露出來