让 IE 文本阴影 Polyfill 与 Modernizr 一起使用
我正在尝试获取一个小的polyfill(https://github.com/heygrady/textshadow)来添加文本阴影效果在 Internet Explorer 上工作,但似乎无法弄清楚如何使其工作。这是我正在使用的代码:
<script src="@Url.Content("~/Scripts/modernizr.custom.61772.min.js")" type="text/javascript"></script>
<script>
Modernizr.load({
test: Modernizr.textshadow,
nope: ['/Content/jquery.textshadow.css', '/Scripts/jquery.textshadow.js'],
complete: function () {
$('h1').textshadow('1px 1px 2px #111')
}
});
</script>
我确实得到了效果,但看起来完全错误。我只是再次得到原始标题文本,其格式与原始文本完全相同,但向底部偏移了半个行高。
编辑:所以经过一些实验,我发现我至少可以通过手动为类创建 CSS 规则来获得阴影效果,而不是依靠 javascript 来实现,如下所示:
h1 .ui-text-shadow-copy
{
color: #111; /* color */
filter:
progid:DXImageTransform.Microsoft.Blur(makeShadow=false,pixelRadius=2); /* blue */
left: 0px; /* left - blur */
top: 0px; /* top - blur */
}
但定位仍然搞砸了。左侧 0px,顶部 0px,阴影放置在文本下方半行。与其他任何东西一样,阴影的碎片会散布在页面周围。
I am trying to get a small polyfill (https://github.com/heygrady/textshadow) to add text-shadow effect on Internet Explorer to work, but can't seem to figure out how to make it work. This is the code I'm using:
<script src="@Url.Content("~/Scripts/modernizr.custom.61772.min.js")" type="text/javascript"></script>
<script>
Modernizr.load({
test: Modernizr.textshadow,
nope: ['/Content/jquery.textshadow.css', '/Scripts/jquery.textshadow.js'],
complete: function () {
$('h1').textshadow('1px 1px 2px #111')
}
});
</script>
I do get an effect but it looks all wrong. I just end up with the original heading text all over again, with the exact same formatting as the original text, but offset towards the bottom by half a line height.
EDIT: So after some experimenting I found out that I can at least get the shadow effect by manually creating the CSS rules for the class, rather than relying on javascript to do so, like so:
h1 .ui-text-shadow-copy
{
color: #111; /* color */
filter:
progid:DXImageTransform.Microsoft.Blur(makeShadow=false,pixelRadius=2); /* blue */
left: 0px; /* left - blur */
top: 0px; /* top - blur */
}
But the positioning is still screwed up. With left 0px and top 0px the shadow is placed half a line below the text. With anything else pieces of the shadow is spread out around the page.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
我让它工作,但我必须重写 .textshadow 方法内的 css 样式才能使其看起来正确。以下是对我有用的方法:
支持文本阴影的浏览器的 CSS:
Modernizr.load:
document.ready.js:
最终结果足够接近,以至于大多数用户永远不会知道 IE、Chrome 和 Firefox 之间的区别。
I got it to work but I had to override the css styling inside the .textshadow method to get it to look right. Here's what worked for me:
CSS for browsers that support text-shadow:
Modernizr.load:
document.ready.js:
The end result is close enough that the majority of users would never know the difference between IE, Chrome, and Firefox.
尝试使用 Microsoft
DropShadow
css 过滤器:其中:
Try to use Microsoft
DropShadow
css filter for that:Where:
简单的答案:忘记 IE 中的文本阴影。没有任何可用的东西可以渲染得足够接近其他浏览器。
Simple answer: forget about text-shadow in IE. There is nothing available that can render close enough to other browsers.
您可以使用 Css3Pie 进行文本阴影和边框半径:
http://css3pie.com/
you can use Css3Pie to text-shadow and border-radius:
http://css3pie.com/