@@ -264,17 +264,21 @@ export default (Vue as VueConstructor<Vue & {
264
264
/** 定位下拉框 */
265
265
locateDropdown (): void {
266
266
const referenceRect = this .$refs .reference .getBoundingClientRect ()
267
- const referenceWidth = referenceRect .right - referenceRect . left
268
- const referenceHeight = referenceRect .bottom - referenceRect . top
267
+ const referenceWidth = referenceRect .width
268
+ const referenceHeight = referenceRect .height
269
269
270
270
// Set dropdown width
271
271
const minWidth = ` ${typeof this .dropdownMinWidth === ' number' ? this .dropdownMinWidth : referenceWidth }px `
272
272
this .$refs .dropdown .style .minWidth = minWidth
273
273
this .$refs .dropdown .style .width = this .dropdownWidthFixed ? minWidth : ' auto'
274
274
275
275
const dropdownRect = this .$refs .dropdown .getBoundingClientRect ()
276
- const dropdownWidth = dropdownRect .right - dropdownRect .left
277
- const dropdownHeight = dropdownRect .bottom - dropdownRect .top
276
+ const dropdownStyleDeclaration = window .getComputedStyle (this .$refs .dropdown )
277
+ const dropdownMarginHorizontal = parseFloat (dropdownStyleDeclaration .marginLeft ) + parseFloat (dropdownStyleDeclaration .marginRight )
278
+ const dropdownMarginVertical = parseFloat (dropdownStyleDeclaration .marginTop ) + parseFloat (dropdownStyleDeclaration .marginBottom )
279
+ const dropdownWidth = dropdownRect .width + dropdownMarginHorizontal
280
+ // 0.8 这个值写在 css 里,因为有动画,所以获取到的是 scaleY 变换后的值
281
+ const dropdownHeight = dropdownRect .height / 0.8 + dropdownMarginVertical
278
282
let top = 0
279
283
let left = 0
280
284
if (this .transfer ) {
@@ -302,7 +306,7 @@ export default (Vue as VueConstructor<Vue & {
302
306
case ' bottom' :
303
307
if (this .transfer ) {
304
308
top = window .pageYOffset + referenceRect .bottom
305
- left = window .pageXOffset + referenceRect .right - dropdownWidth
309
+ left = ( window .pageXOffset + referenceRect .right - dropdownWidth ) / 2
306
310
} else {
307
311
top = referenceHeight
308
312
left = (referenceWidth - dropdownWidth ) / 2
@@ -328,7 +332,7 @@ export default (Vue as VueConstructor<Vue & {
328
332
case ' top' :
329
333
if (this .transfer ) {
330
334
top = window .pageYOffset + referenceRect .top - dropdownHeight
331
- left = window .pageXOffset + referenceRect .right - dropdownWidth
335
+ left = ( window .pageXOffset + referenceRect .right - dropdownWidth ) / 2
332
336
} else {
333
337
top = - dropdownHeight
334
338
left = (referenceWidth - dropdownWidth ) / 2
0 commit comments