首页 > 技术文章 > van-tab吸顶后头部透明色渐变响应

wd163 2020-04-29 09:37 原文

 

 方法一:监听滚动事件

$('.scrollContent').bind('touchmove', function(e){
            var  winHeight = $(window).scrollTop()
            document.getElementById('opacityHeader').style.opacity=winHeight*0.01   
            document.getElementById('centerBg').style.opacity=1-winHeight*0.01   
        })
方法二:使用van-tab的scroll事件
van-tabs标签内添加
@scroll='scroll'
methods内:
scroll(){
        // debugger
        let winHeight = $(window).scrollTop()
        console.log(winHeight)
        document.getElementById('渐变色div的id').style.opacity=winHeight*0.01 
      },

推荐阅读