diff --git a/packages/taro-components/src/components/map/map.tsx b/packages/taro-components/src/components/map/map.tsx index 8299671b50d9..6430a7e45316 100644 --- a/packages/taro-components/src/components/map/map.tsx +++ b/packages/taro-components/src/components/map/map.tsx @@ -949,7 +949,9 @@ export class Map implements ComponentInterface { // 创建 img 元素并设置样式 const img = document.createElement('img') img.src = this._imageUrl - img.style.opacity = this._opacity + // 确保opacity值在0到1之间 + const validOpacity = (this._opacity < 0 ) ? '1' : this._opacity + img.style.opacity = validOpacity div.appendChild(img) this._div = div } @@ -995,7 +997,8 @@ export class Map implements ComponentInterface { this._div.style.width = imageWidth + 'px' this._div.style.height = imageHeight + 'px' this._div.style.display = this._visible ? 'block' : 'none' - this._div.getElementsByTagName('img')[0].style.opacity = this._opacity + const validOpacity = (this._opacity < 0 ) ? '1' : this._opacity + this._div.getElementsByTagName('img')[0].style.opacity = validOpacity } // 创建 GroundOverlay 实例 @@ -1031,7 +1034,8 @@ export class Map implements ComponentInterface { const imgElement = element.querySelector('img') if (imgElement) { // 找到了对应的元素 - element.style.opacity = opacity + const validOpacity = (opacity < 0 ) ? '1' : opacity + element.style.opacity = validOpacity imgElement.style.display = visible ? 'block' : 'none' element.style.zIndex = zIndex