从数组翻转调用图像

Rollover calling image from array

在一个网页上工作,我想从同一个基本图像进行多次翻转(多个黑色像素分布在整个页面 - 有点像弹出效果)。我认为最简单的方法是拥有一个包含所有翻转图像的数组和一个包含基本图像的数组 (pixel.png)。甚至让图像显示都遇到了很多麻烦,现在我已经显示了背景图像,我无法让翻转工作。已尝试使用 developer/debug 在 chrome 中解决问题,但没有骰子 - 甚至不显示错误消息。我猜这是一些简单的事情,比如没有正确调用函数,但我就是看不到它..

<!DOCTYPE html>
<html>
<head>
<script type="text/javascript">
            var revert = new Array('pixel.png');
            var inames = new Array('black1off.jpg', 'black2off.jpeg');

         //preload
            if (document.images) {
                var flipped = new Array();
                  for(i=0; i< inames.length; i++) {
                        flipped[i] = new Image();
                        flipped[i] = "media/"+inames[i];
                      }
                    }

            function over(num) {
              if(document.images) {
                revert[num] = document.images[inames[num]];
                document.images[inames[num]] = flipped[num];
              }
            }
            function out(num) {
              if(document.images) {
                document.images[inames[num]] = revert[num];
             }              
            }

 </script>
 </head>
 <body>
 <body bgcolor="#000000">

    <img src="media/pixel.png" name="pixel" height="50px" width="50px" style="position:absolute; top:30px; left:50px;" onMouseOver="over(0)" onMouseOut="out(0)">
    <img src="media/pixel.png" name="pixel" height="50px" width="50px" style="position:absolute; top:30px; left:200px;" onMouseOver="over(1)" onMouseOut="out(1)"> 
  </body>
  </html>

这很简单,但您发布的内容还差得远:

这是工作示例:https://jsfiddle.net/tqw84trm/1/

if (document.images) {
  var flipped = new Array();
  for(i=0; i< inames.length; i++) {
    flipped[i] = new Image();
    flipped[i].src = "media/"+inames[i];
  }
}

function out (num) {
  if(document.images) {
    var rev = revert.slice();
    revert[num] = document.images[num].src;
    document.images[num].src = rev[num];
  }              
}