0

在一个网页上工作,我希望从同一个基本图像中进行多次翻转(多个黑色像素分布在整个页面中 - 有点像弹出效果)。我认为最简单的方法是拥有一个包含所有翻转图像的数组和一个包含基本图像(pixel.png)的数组。甚至让图像显示也遇到了很多麻烦,现在我已经显示了背景图像,我无法让翻转工作。尝试使用开发人员/调试在 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>
4

1 回答 1

1

这很简单,但您发布的内容甚至不接近:

这是工作示例: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];
  }              
}
于 2016-04-24T01:15:06.943 回答