-1

可能重复:
如何在 IE 中使用 HTML5 画布元素?

我不确定我做错了什么。我按照它说的做了,但没有任何效果。我正在使用网格系统,但我认为这不是问题所在。而且我也不认为这是我的安全设置。如果有帮助,这是我的 HTML 和 Javascript。

HTML

<html lang="en">
  <head>
    <meta charset="utf-8" />
    <title>Zack Vivier</title>
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <!--[if IE]><script type="text/javascript" src="js/excanvas.js"></script><![endif]-->
    <!-- enable HTML5 elements in IE7+8 -->
    <!--[if lt IE 9]>
    <script src="js/html5shiv.js"></script>
    <![endif]-->
    <!-- 1140px Grid styles for IE -->
    <!--[if lte IE 9]><link rel="stylesheet" href="styles/ie.css" type="text/css" media="screen" /><![endif]-->
    <link href="styles/styles.css" rel="stylesheet" type="text/css">
    <link href="styles/1140.css" rel="stylesheet" type="text/css">
    <!--css3-mediaqueries-js - http://code.google.com/p/css3-mediaqueries-js/ - Enables media queries in some unsupported browsers-->
    <script type="text/javascript" src="js/css3-mediaqueries.js"></script>
    <script src="js/js.js"></script>
  </head>
  <body>
    <header>
      <h1 class="hidden">Zack Vivier Home</h1>
      <div class="container">
        <div class="row">
          <div class="fivecol">
            <div class="logo"><img src="images/logo.png" alt="zack vivier logo"></div>
          </div>
          <div class="sevencol last">
            <nav>
              <h2 class="hidden">Site Navigation</h2>
              <ul>
                <li><a href="index.html">Home</a></li>
                <li><a href="info.html">Information</a></li>
                <li><a href="portfolio.html">Portfolio</a></li>
                <li><a href="contact.html">Contact</a></li>
              </ul>
            </nav>
          </div>
        </div>
      </div>
    </header>
    <div class="container">
      <div class="row">
        <div class="twelvecol last">
          <div class="lineone"></div>
        </div>
      </div>
    </div>
    <div class="container">
      <div class="row">
        <div class="twelvecol last">
          <div class="caption">
            <h4 id="tagLine">Image Number</h4>
          </div>
          <div class="slideshow">
            <canvas id='showCanvas' width='1022' height='397'>Canvas Not Supported</canvas>
          </div>
        </div>
      </div>
    </div>
    <div class="container">
      <div class="row">
        <div class="threecol last">
          <div class="about"><h2>About Me</h2></div>
        </div>
      </div>
    </div>
    <div class="container">
      <div class="row">
        <div class="twelvecol last">
          <div class="linetwo"></div>
        </div>
      </div>
    </div>
    <div class="container">
      <div class="row">
        <div class="sevencol last">
          <div class="contenthome">
            <p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; My Name is Zack Vivier; currently I am 19</p>
            <p>years old and attend Fanshawe College for Interactive</p>
            <p>Media Design and Production. I am a Designer,</p
            <p>Programmer, Musician, Video Editor, and Animator.</p>
          </div>
        </div>
      </div>
    </div>
    <h1 class="hidden">footer</h1>
    <div class="container">
      <div class="row">
        <div class="twelvecol last">
          <div class="footer">
            <h3>Copyright &copy; 2012 Zack Vivier. All Rights Reserved.</h3>
          </div>
        </div>
      </div>
    </div>
  </body>
</html>

Javascript

// JavaScript Document
var imagePaths = new Array("images/photo_1.png", "images/game_web.jpg", "images/tattoo.jpg");
var whichImage = new Array("Graffti Project", "Game WebSite", "Tattoo Project");
var showCanvas;
var showCanvasCtx;
var imageText;
var currentImage = 0;
var currentImageText = 0;
var img = document.createElement("img");
function init() {
  imageText=document.getElementById('tagLine');
  showCanvas = document.getElementById('showCanvas');
  showCanvasCtx = showCanvas.getContext('2d');
  img.setAttribute('width','1022');
  img.setAttribute('height','397');
  switchImage();
  setInterval(switchImage, 2500);
}
function switchImage() {
  imageText.innerHTML = whichImage[currentImageText++];
  img.setAttribute('src',imagePaths[currentImage++]);
  img.onload = function() {
    if (currentImage >= imagePaths.length) {
      currentImage = 0;
      currentImageText = 0;
    }
    showCanvasCtx.drawImage(img,0,0,1022,397);
  }
  window.onload = init();
4

2 回答 2

0

Canvas 是 IE8 不支持的 HTML5 元素。您的文档类型也是错误的,因为您使用的是 HTML5 将其设置为:“”。

于 2012-12-05T08:18:38.297 回答
0

正如评论中所说:IE8 将不支持 canvas 标签。但是有一些插件可以模仿它的行为。我曾经使用过这个:http: //flashcanvas.net/,它可以完成这项工作,还有另一个叫做http://code.google.com/p/explorercanvas/。但我对此没有任何评论,从未使用过,不知道会发生什么。

只需注意一点:后备方案有其局限性,但就 2D 绘图而言,我认为这些对你有用

于 2012-12-05T08:19:01.993 回答