头图

文档:uni.getSystemInfoSync
通过getSystemInfo异步获取系统信息
通过getSystemInfoSync同步获取系统信息
这里返回的uniPlatform表示运行的平台,如果是App运行则返回'app',如果是H5运行则返回'web',如果是微信小程序运行,则返回'微信小程序'
详情如下:

生效条件
appApp
webWeb
mp-weixin微信小程序
mp-alipay支付宝小程序
mp-baidu百度小程序
mp-toutiao抖音小程序
mp-lark飞书小程序
mp-qqQQ小程序
mp-kuaishou快手小程序
mp-jd京东小程序
mp-360360小程序
quickapp-webview快应用通用(包含联盟、华为)
quickapp-webview-union快应用联盟
quickapp-webview-huawei快应用华为

在这里我通过运行平台判断滚动滑块的粘连高度:

getSystem(){
    let data = uni.getSystemInfoSync();
    let stickyHeight = 0;
    if (data.uniPlatform == 'web') {
        stickyHeight = 1250;
    } else if (data.uniPlatform == 'app') {
        stickyHeight = 1300;
    } else {
        stickyHeight = 1250;
    }
}

有些时候还需要区分机型,因为同平台的不同机型渲染会有差异,此时可以用uniPlatform + deviceType + system 等条件组合判断


兔子先森
466 声望556 粉丝

致力于新技术的推广与优秀技术的普及。