我用pictureFill在我的网页上加载了一些图片。它们在chrome中显示正确,但在internet explorer 8中根本不显示。
以下是我的代码示例:
<link href="styles.css" rel="stylesheet" type="text/css">
<script src="js/modernizr.custom.11641.js"></script>
<script async="true" src="js/picturefill.js"></script>
<script src="js/respond.js"></script>
</head>
<body>
<div class="wrapper">
<header class="x-padding inside-b-padding">
<h1 class="nocontent outline">Baseball for Busy
People</h1>
<picture class="logo">
<!--[if IE 9]><video style="display: none;"><![endif]-->
<source srcset="images/logo.png" media="(min-width: 750px)">
<!--[if IE 9]></video><![endif]-->
<img srcset="images/logo-small.png" alt="Baseball for Busy People">
</picture>
(我包括了最上面的部分,以防我的文件链接是问题的一部分)。
我可以在ie 8:http://scottjehl.github.io/picturefill/examples/demo-02.html中查看演示。但我页面上的图片不起作用。
我试过的是:
我从演示中复制并粘贴了代码到我的页面(将图像路径更改为绝对路径)-它们没有显示。
我添加了脚本来创建一个
<picture>
元素(尽管我使用的是modernisr,所以不需要它)。我在img标记中添加了一个src路径,这很有效,但是我看到picturefill不推荐这样做。
最佳答案
我知道这个问题是很久以前提过的,但也许这能帮助其他遇到类似问题的人。我也遇到过同样的问题,在我的网站上,没有在不支持图片的浏览器中加载图片(例如IE9-IE11)。修复方法是确保在将元素添加到页面时调用pictureFill()(我在angular指令中调用它,在react中调用componentDidMount)。