Browse Source

fix: 视频背景固定

王晓东 3 tháng trước cách đây
mục cha
commit
9ca5b0f8d6
1 tập tin đã thay đổi với 2 bổ sung39 xóa
  1. 2 39
      src/components/page-wrapper/CustomBg.tsx

+ 2 - 39
src/components/page-wrapper/CustomBg.tsx

@@ -27,45 +27,7 @@ const Index: React.FC<Props> = ({styleBg}) => {
 
   const isMp4 = bg?.lastIndexOf('.mp4') > -1
 
-  // useEffect(()=> {
-  //   if(!bg) {
-  //     return;
-  //   }
-  //   if(isMp4){
-  //     return 
-  //   }
-  //   Taro.getImageInfo({
-  //     src: bg,
-  //     success(res) {
-  //       const imgWidth = res.width;
-  //       const imgHeight = res.height;
-
-  //       let ratio = windowHeight / imgHeight;
-  //       let scaledWidth = imgWidth * ratio;
-  //       let scaledHeight = windowHeight;
-  //       let offsetX = 0;
-  //       let offsetY = 0;
-
-  //       if (scaledWidth >= windowWidth) {
-  //         offsetX = (scaledWidth - windowWidth) / 2;
-  //         offsetY = 0;
-  //       } else {
-  //         ratio = windowWidth / imgWidth;
-  //         scaledWidth = windowWidth;
-  //         scaledHeight = imgHeight * ratio;
-  //         offsetX = 0;
-  //         offsetY = (scaledHeight - windowHeight) / 2;
-  //       }
-
-  //       setOffsetMargin({ x: -offsetX, y: -offsetY });
-  //       setBgSize({ width: scaledWidth, height: scaledHeight });
-  //     },
-  //     fail(err) {
-  //       console.error('获取图片信息失败', err)
-  //     }
-  //   })
-  // }, [styleBg])
-
+  //todo: 无法计算图的大小来设置位置,因为获取图片宽,高信息需要异步获取
   if(!bg) {
     return <></>
   }
@@ -79,6 +41,7 @@ const Index: React.FC<Props> = ({styleBg}) => {
       autoplay
       objectFit="cover"
       className={pageStyle.bg}
+      style={bgImageStyle}
       src={bg}
     />
   }