@@ -109,31 +109,48 @@ const Affix = defineComponent({
109
109
const newState = {
110
110
status : AffixStatus . None ,
111
111
} as AffixState ;
112
- const targetRect = getTargetRect ( targetNode ) ;
113
112
const placeholderRect = getTargetRect ( placeholderNode . value as HTMLElement ) ;
113
+
114
+ if (
115
+ placeholderRect . top === 0 &&
116
+ placeholderRect . left === 0 &&
117
+ placeholderRect . width === 0 &&
118
+ placeholderRect . height === 0
119
+ ) {
120
+ return ;
121
+ }
122
+
123
+ const targetRect = getTargetRect ( targetNode ) ;
114
124
const fixedTop = getFixedTop ( placeholderRect , targetRect , offsetTop . value ) ;
115
125
const fixedBottom = getFixedBottom ( placeholderRect , targetRect , offsetBottom . value ) ;
126
+
116
127
if ( fixedTop !== undefined ) {
128
+ const width = `${ placeholderRect . width } px` ;
129
+ const height = `${ placeholderRect . height } px` ;
130
+
117
131
newState . affixStyle = {
118
132
position : 'fixed' ,
119
133
top : fixedTop ,
120
- width : placeholderRect . width + 'px' ,
121
- height : placeholderRect . height + 'px' ,
134
+ width,
135
+ height,
122
136
} ;
123
137
newState . placeholderStyle = {
124
- width : placeholderRect . width + 'px' ,
125
- height : placeholderRect . height + 'px' ,
138
+ width,
139
+ height,
126
140
} ;
127
141
} else if ( fixedBottom !== undefined ) {
142
+ const width = `${ placeholderRect . width } px` ;
143
+ const height = `${ placeholderRect . height } px` ;
144
+
128
145
newState . affixStyle = {
129
146
position : 'fixed' ,
130
147
bottom : fixedBottom ,
131
- width : placeholderRect . width + 'px' ,
132
- height : placeholderRect . height + 'px' ,
148
+ width,
149
+ height,
133
150
} ;
134
151
newState . placeholderStyle = {
135
- width : placeholderRect . width + 'px' ,
136
- height : placeholderRect . height + 'px' ,
152
+ width,
153
+ height,
137
154
} ;
138
155
}
139
156
0 commit comments