【发布时间】:2019-09-27 21:54:35
【问题描述】:
我创建了一个虚拟的ReactJS 组件:Frame,它在Chrome 上渲染得很好,但在Edge 上渲染得不好。
这里有Codesandbox.io:
https://codesandbox.io/s/o4kw405n69
这里有它在它们上的渲染方式:
在 Chrome 上(良好):
在 Microsoft Edge(坏)上:
您可以在这两种浏览器上自行尝试:
https://0okjypwknl.codesandbox.io/
为了创建框架,我只使用了一张简单的图片:
然后,经过一些CSS 转换后,我得到了想要的效果,包括角落。
不幸的是,在Edge 上,我在其他角落没有得到想要的效果。您对如何为Edge 解决这个问题有任何想法吗?当然,让Chrome 继续工作?
请在上面 fork 我的Codesandbox.io:https://codesandbox.io/s/o4kw405n69,应用您的解决方案并将链接粘贴到此处。
顺便说一下,这里的样式负责进行所需的转换以获得框架效果:
this.style = {
frame: {
position: 'absolute',
width: widthFrame + 'px',
height: heightFrame + 'px',
...((urlImageMat !== false) && {
backgroundImage: 'url("' + urlImageMat + '")',
}),
},
image: {
backgroundImage: 'url("' + urlImageMain + '")',
backgroundRepeat: 'no-repeat',
backgroundSize: widthImage + 'px ' + heightImage + 'px',
backgroundPosition: 'center',
width: '100%',
height: '100%',
},
trapezoidTop: {
width: widthFrame + 'px',
height: thickFrame + 'px',
clipPath: 'polygon(0 0, 100% 0, calc(100% - ' + thickFrame + 'px) 100%, ' + thickFrame + 'px 100%)',
transformOrigin: 'top left',
transform: 'rotate(0deg)',
},
trapezoidLeft: {
width: heightFrame + 'px',
height: thickFrame + 'px',
marginTop: - thickFrame + 'px',
clipPath: 'polygon(0 0, 100% 0, calc(100% - ' + thickFrame + 'px) 100%, ' + thickFrame + 'px 100%)',
transformOrigin: 'top left',
transform: 'rotate(90deg) scale(1, -1)',
},
trapezoidImage: {
backgroundImage: 'url("' + urlImageFrame + '")',
backgroundSize: 'contain',
},
edgeTLBR: {
position: 'absolute',
},
edgeBR: {
display: 'inline-block',
width: widthFrame + 'px',
height: heightFrame + 'px',
transform: 'rotate(180deg)',
},
};
(更多详情请关注Codesandbox.io)
谢谢!
【问题讨论】:
-
这基本上是 stackoverflow.com/questions/39477755/… 的欺骗(Edge 不支持 HTML 上的
clip-path也不支持<basic-shape>CSS 值。现在,您的问题可能还有其他解决方案,而不是那里暴露的问题,所以我暂时把妙尔尼尔放在口袋里。
标签: javascript reactjs css jsx