scroll-view如果先hidden再出现,scroll-into-view无效
<scroll-view scroll-y style= "height: 200px;" scroll-into-view= "yellow" hidden> <view id= "green" class= "scroll-view-item bc_green" ></view> <view id= "red" class= "scroll-view-item bc_red" ></view> <view id= "yellow" class= "scroll-view-item bc_yellow" ></view> <view id= "blue" class= "scroll-view-item bc_blue" ></view> </scroll-view> |
先hidden,然后通过setData把hidden去掉,此时scroll-into-view无效
把hidden去掉的同时给scroll-into-view重新赋值
好像并不行
我这里scroll-into-view的值都没有用变量,直接写死的
得用{{}}的方式来 就算是你的值不打算改变 也要重新赋值一下
行了.....感谢!
刚刚测试了,有效。
<
view
wx:if
=
'{{show}}'
>
<
scroll-view
scroll-y
style
=
"height: 200px;"
scroll-into-view
=
"{{intoView}}"
>
<
view
wx:for
=
'{{list}}'
wx:key
=
'id{{index}}'
id
=
"{{item}}"
class
=
"scroll-view-item bc_{{item}}"
></
view
>
</
scroll-view
>
</
view
>
<
view
class
=
"btn-area"
>
<
button
size
=
"mini"
bindtap
=
"tap"
>点击让scroll-view出现</
button
>
</
view
>
Page({
data: {
show:
false
,
intoView:
null
,
list: [
'green'
,
'red'
,
'yellow'
,
'blue'
]
},
onLoad:
function
() {
},
tap:
function
(e) {
this
.setData({
show:
true
,
intoView:
'yellow'
})
},
})
.scroll-view-item {
width
:
100%
;
height
:
100px
;
}
.bc_green {
background
:
green
;
}
.bc_red {
background
:
red
;
}
.bc_yellow {
background
: yellow;
}
.bc_blue {
background
:
blue
;
}
你好,麻烦提供能复现问题的简单代码片段(https://developers.weixin.qq.com/miniprogram/dev/devtools/minicode.html)
wechatide://minicode/9wdxXZmK6mZW