收藏
回答

在scroll-view里添加元素时怎么让滚动条始终在最下面

wxml

<view class="container">
  <scroll-view scroll-y='true' style="height:500rpx;background:#ccc">
    <view class="item" wx:for="{{list}}">
      <text>{{item.text}}</text>
    </view>
  </scroll-view>
  <button class='btn' bindtap="push" data-index="{{list.length}}">push</button>
</view>

js

Page({
  data: {
    list:[
      { text: '我是01' },
      {text: '我是02' },
      {text: '我是03' },
      {text: '我是04' },
      {text: '我是05' },
      {text: '我是06' },
      {text: '我是07' },
      {text: '我是08' },
      {text: '我是09' },
      {text:'我是10'}
    ]
  },
  push:function(e){
    var index = e.target.dataset.index;
    var obj = {};
    obj.text = '我是' + (index+1);
    this.data.list.push(obj);
    this.setData({
      list: this.data.list
    })
  }
})


初始化状态


点击push追加,当出现滚动条时,如何让滚动条始终在最下面显示最新内容呢




回答关注问题邀请回答
收藏

5 个回答

  • 人生如戏
    人生如戏
    2017-06-14

    scrollintoview  这个方法可以,谢谢各位,已解决

    2017-06-14
    有用
    回复
  • You can you up
    You can you up
    2017-06-14

    设的非常大的直接  你试试 我做的是让他保持在顶部  没法试试你的问题

    2017-06-14
    有用
    回复
  • 迷惘
    迷惘
    2017-06-14

    scrollintoview,在最底部加个隐藏的或者高度很低的view,id叫scrollBottom,然后setData({scrollIntoView: 'scrollBottom'})就可以了

    2017-06-14
    有用
    回复
  • 人生如戏
    人生如戏
    2017-06-14

    scroll-view里面文档的实际高度无法获取啊,算不了

    2017-06-14
    有用
    回复
  • You can you up
    You can you up
    2017-06-14

    scroll-top="{{scrollTop}}"


    scrollTop变量 通过计算算

    2017-06-14
    有用
    回复
登录 后发表内容