weex里面怎么实现滚动到指定位置和动态改变背景

目前用weex框架写app,遇到以下3个问题,求大神赐教。
1.根据导航栏的tab不同,点击滚动到指定位置。类似京东楼梯效果
2.导航栏滚动到顶部时固定在顶部。
3.当前页面的背景颜色根据路由的id动态改变,weex没有document对象,传统的方法实现不了这个功能,请教大神。
前两个属于同一个问题,获取滚动距离。第3个是动态改变颜色,两种颜色还比较好换,关键是我这里有8种不同的颜色,有没有童鞋遇到过这个问题的,求教

阅读 6.4k
1 个回答

1、可以使用内建模块dom的scrollToElement(node, options)API,让页面滚动到那个对应的节点写法请见-> http://weex.apache.org/cn/references/modules/dom.html#scrollToElement-node-options
2、使用position: sticky;,针对你的需求的一种布局方式,以下代码为简写

<div class="wrapper">
   <text style="position: sticky;">导航栏</text>
</div>

3、使用内建模块animation的transition(el, options, callback)API http://weex.apache.org/cn/references/modules/animation.html#transition-el-options-callback
以下代码为简写


<script>
  const animation = weex.requireModule('animation')
  export default {
    data () {
      return {
          bgColor:{
              "r1":"#111",
              "r2":"#222",
              "r3":"#333",
              "r4":"#444",
              "r5":"#555",
              "r6":"#666",
              "r7":"#777",
              "r8":"#888"
          }
      }
    },
    methods: {
      changeBackground (_router) {
        var _target = this.$refs.target;
        animation.transition(_target, {
          styles: {
            backgroundColor: this.bgColor[_router]
          },
          duration: 800, //变换用时,可设置为0
          timingFunction: 'ease',//变换的动画,同理css3变换
          delay: 0 //延时执行
        })
      }
    }
  }
</script>

以上三点希望对你有所帮助

撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进
推荐问题