87、最简单的图片变换

87、最简单的图片变换

脚本说明:

把如下代码加入<body>区域中

<script type="text/javascript">

function init() {

  if (!document.getElementById) return

  var imgOriginSrc;

  var imgTemp = new Array();

  var imgarr = document.getElementsByTagName('img');

  for (var i = 0; i < imgarr.length; i++) {

    if (imgarr[i].getAttribute('hsrc')) {

        imgTemp[i] = new Image();

        imgTemp[i].src = imgarr[i].getAttribute('hsrc');

        imgarr[i].onmouseover = function() {

            imgOriginSrc = this.getAttribute('src');

            this.setAttribute('src',this.getAttribute('hsrc'))

        }

        imgarr[i].onmouseout = function() {

            this.setAttribute('src',imgOriginSrc)

        }

    }

  }

}

onload=init;

 

</script>

<img src="1840.gif" hsrc="1841.gif">

<img src="1841.gif" hsrc="1842.gif">

 

Write a comment

Comments: 0