通过 Javascript/CSS 跨浏览器翻转 html/图像?
有没有库/简单的方法来翻转图像?
像这样翻转图像:
AABBCC CCBBAA
AABBCC -> CCBBAA
我不是在寻找动画,只需翻转图像即可。
我用谷歌搜索没有找到avial,只找到了一个在 MozillaZine 我不相信它能跨浏览器工作。
Is there a library/simple way to flip an image?
Flip image like this:
AABBCC CCBBAA
AABBCC -> CCBBAA
I'm not looking for animations, just flip the image.
I've googled to no avial and only found a complex version that utilized SVG on MozillaZine which I'm not confident that it'll work cross-browser.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
以下 CSS 将在 IE 和支持 CSS 转换的现代浏览器中运行。我提供了一个垂直翻转课程,以防万一您也想使用它。
The following CSS will work in IE and modern browsers that support CSS transforms. I included a vertical flip class just in case you might want to use it too.
看一下众多 reflection.js 类型库之一,它们非常简单。在 IE 中,他们将采用“flipv”过滤器,也有一个“fliph”过滤器。在其他浏览器中,它将创建一个canvas标签并使用drawImage。虽然 Elijah 的回答可能支持相同的浏览器。
Take a look at one of the many reflection.js type libraries, They are pretty simple. In IE they will take and use the 'flipv' filter, there is a 'fliph' filter too. Inside of other browsers, it will create a canvas tag and use the drawImage. Although Elijah's answer probably supports the same browsers.
只是在尝试修复错误时挖出了这个答案,虽然建议的答案是正确的,但我发现它打破了大多数现代 CSS Linting 规则,即包含所有供应商转换规则。然而,包含 -ms-tranform 规则会在 IE9 中导致一个奇怪的错误,它应用过滤器和 -ms-transform 规则,导致图像翻转并再次翻转回来。
这是我建议的改进,它也支持 CSS Lint 规则:
Just dug up this answer while trying to fix a bug, while the suggested answer is correct I have found that it breaks most modern CSS Linting rules regarding the inclusion of all vendor rules for the transform. However, including the -ms-tranform rule causes an odd bug in IE9 where it applies the filter and -ms-transform rules causing an image to flip and flip back again.
Here is my suggested improvement which also supports CSS Lint rules:
如果您只想翻转背景图像,则可以在翻转的 div 内的内部元素上使用该类。基本上,您将使用主 div 翻转内部元素,但将每个元素翻转回来。无论如何,可以在 Firefox 中使用。
像这样:
If you only want to flip a background image you can use the class on the internal elements inside a flipped div. Basically you're flipping the internal elements with the main div, but flipping each of them back. Works in Firefox anyway.
Like this: