@@ -51,9 +51,53 @@ Component({
51
51
ready : function ( ) {
52
52
instanceManager . setWxCompInst ( this . data . diuu , this )
53
53
this . onScrollFunc = getPropsMethod ( this , 'onScroll' )
54
+
55
+ //onContentSizeChange
56
+ if ( getPropsMethod ( this , 'onContentSizeChange' ) ) {
57
+ const query = wx . createSelectorQuery ( ) . in ( this )
58
+ query . select ( '.scroll-area' ) . boundingClientRect ( ( res ) => {
59
+ this . setData ( {
60
+ contentHeight : res . height
61
+ } )
62
+
63
+ this . watchContentSize ( )
64
+ } ) . exec ( )
65
+ }
54
66
} ,
55
67
56
68
methods : {
69
+ // 监听contentSize的变化
70
+ watchContentSize ( ) {
71
+ const observer = wx . createIntersectionObserver ( this , { observeAll : true } )
72
+ observer . relativeTo ( '.scroll-area' )
73
+ . observe ( '.ball' , ( res ) => {
74
+ const { id, intersectionRatio, relativeRect} = res
75
+ if ( id === 'above' && intersectionRatio === 0 ) {
76
+ const onContentSizeChangeFunc = getPropsMethod ( this , 'onContentSizeChange' )
77
+ onContentSizeChangeFunc ( relativeRect . right - relativeRect . left , relativeRect . bottom - relativeRect . top )
78
+
79
+ const query = wx . createSelectorQuery ( ) . in ( this )
80
+ query . select ( '.scroll-area' ) . boundingClientRect ( ( res ) => {
81
+ this . setData ( {
82
+ contentHeight : res . height
83
+ } )
84
+ } ) . exec ( )
85
+ }
86
+
87
+ if ( id === 'below' && intersectionRatio === 1 ) {
88
+ const onContentSizeChangeFunc = getPropsMethod ( this , 'onContentSizeChange' )
89
+ onContentSizeChangeFunc ( relativeRect . right - relativeRect . left , relativeRect . bottom - relativeRect . top )
90
+
91
+ const query = wx . createSelectorQuery ( ) . in ( this )
92
+ query . select ( '.scroll-area' ) . boundingClientRect ( ( res ) => {
93
+ this . setData ( {
94
+ contentHeight : res . height
95
+ } )
96
+ } ) . exec ( )
97
+ }
98
+ } )
99
+ } ,
100
+
57
101
scrollTo ( pos ) {
58
102
const { x, y } = pos ;
59
103
this . setData ( { outTop : y , outLeft : x } )
@@ -88,5 +132,6 @@ Component({
88
132
withAni : true ,
89
133
outLeft : 0 ,
90
134
outTop : 0 ,
135
+ contentHeight : 0 ,
91
136
}
92
137
} ) ;
0 commit comments