diff --git a/packages/taro-platform-harmony/src/components/components-harmony-ets/style.ets b/packages/taro-platform-harmony/src/components/components-harmony-ets/style.ets index 08ad4d28ced..5df8a34458f 100644 --- a/packages/taro-platform-harmony/src/components/components-harmony-ets/style.ets +++ b/packages/taro-platform-harmony/src/components/components-harmony-ets/style.ets @@ -369,16 +369,20 @@ export function setNormalAttributeIntoInstance(instance: CommonAttribute, style: } if (style.position === 'absolute' || style.position === 'fixed') { instance.position({ - x: style.left || 0, - y: style.top || 0, + left: style.left, + top: style.top, + right: style.right, + bottom: style.bottom, }) // 绝对定位和固定定位在web上都会脱离文档流,因此需要设置zIndex让它相比正常流的元素更上层 instance.zIndex(1) } if (style.position === 'relative') { instance.offset({ - x: style.left || 0, - y: style.top || 0, + left: style.left, + top: style.top, + right: style.right, + bottom: style.bottom, }) // 绝对定位和固定定位在web上都会脱离文档流,因此需要设置zIndex让它相比正常流的元素更上层 instance.zIndex(1) diff --git a/packages/taro-platform-harmony/src/runtime-ets/dom/stylesheet/covertWeb2Hm.ts b/packages/taro-platform-harmony/src/runtime-ets/dom/stylesheet/covertWeb2Hm.ts index c49c68c8306..5307ace5199 100644 --- a/packages/taro-platform-harmony/src/runtime-ets/dom/stylesheet/covertWeb2Hm.ts +++ b/packages/taro-platform-harmony/src/runtime-ets/dom/stylesheet/covertWeb2Hm.ts @@ -594,9 +594,9 @@ function setBackgroundPosistion (hmStyle, value) { } else if (horizontal === 'right' && vertical === 'bottom') { hmStyle.backgroundPosition = Alignment.BottomEnd } else { - if (/^\d+(\.\d+)?(px|%|vw|vh)$/.test(horizontal)) { + if (/^-?\d+(\.\d+)?(px|%|vw|vh)$/.test(horizontal)) { hmStyle.backgroundPosition = { x: getUnit(horizontal) } - if (/^\d+(\.\d+)?(px|%|vw|vh)$/.test(vertical)) { + if (/^-?\d+(\.\d+)?(px|%|vw|vh)$/.test(vertical)) { hmStyle.backgroundPosition = { x: getUnit(horizontal), y: getUnit(vertical) } } }