html52.com
我爱小程序-开发者交流社区

页面滚动时根据滚动高度动态设置页面元素背景颜色,会出现这部分变成黑色的现象

问题模块 框架类型 问题类型 终端类型 微信版本 基础库版本
框架 小程序 Bug 客户端 7.0.4 2.7.1

在页面滚动监听元素中根据滚动高度动态设置某个值,根据这个值控制元素背景颜色切换,到顶部要无背景,在iphone环境中会出现元素背景变成黑色的情况

建议使用iphone8 plus尝试


js代码

onPageScroll: function (e) {

    if (e.scrollTop > 5) {

        this.setData({

            scrollTop: false

        })

    } else {

        this.setData({

            scrollTop: true

        })

    }

}

wxml代码

<view style="width:100%;height:200vh;">

    <view class='tabTitle' style='padding-top:{{tabInfo.top}}px;line-height:{{tabInfo.height}}px;{{scrollTop?"":"background:#3CA0DC;"}}'>测试</view>

</view>


css代码

.tabTitle{

    position: fixed;

    top:0;

    left: 0;

    width: 100%;

    text-align: center;

    font-size: 32rpx;

    font-weight: bold;

    background: transparent;

    z-index: 9;

}




}代码片段https://developers.weixin.qq.com/s/Z9wee7m37l9J

评论 抢沙发

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址

真正的个人免签约支付接口

云免签H5支付