マウスオーバーしているときに画像をどんどんチェンジするやつ〜う
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"> <meta http-equiv="Content-Script-Type" content="application/javascript"> <meta http-equiv="Content-Type" content="text/html; charset=utf-8"> <title>TEST</title> <body> <div> <img src="./img/0.gif" alt="aaaa" id="my" > <a href="#" id="map7" onMouseover="image0.start(1)" onMouseout="image0.stop(0)">TEST</a><br> <input type="text" id="v" size="80"> </div> <script type="text/javascript"><!-- var ToggleImage = function () { this.init.apply( this, arguments ); }; ToggleImage.prototype.init = function ( id, wait ) { this.e = document.getElementById( id ); this.w = wait; this.g = [ ]; this.c = 0; this.t = null; var cnt, obj; for( cnt = 0; obj = arguments[ cnt + 2 ]; cnt++ ) { this.g[ cnt ] = new Image(); this.g[ cnt ].src = obj; } return this.max = cnt - 1; }; ToggleImage.prototype.start = function ( n ) { if( 'undefined' !== typeof n ) this.c = n; this.next( this.c ); if( this.t ) this.stop( ); return this.t = setInterval( (function( that ) { return function () { that.next(); }; })( this ), this.w ); }; ToggleImage.prototype.next = function ( n ) { this.c = ( 'undefined' === typeof n ) ? this.c + 1: n; if( this.c > this.max ) this.c = 0; return this.e.setAttribute('src', this.g[ this.c ].src); //this.e.src=this.g[ this.c ].src; }; ToggleImage.prototype.stop = function ( n ) { clearInterval( this.t ); if( 'undefined' !== typeof n ) this.next( n ); return this.t = null; }; var image0 = new ToggleImage( 'my', 300, './img/0.gif', './img/1.gif', './img/2.gif' ); //ぜんかくくうはくは、はんかくにでもなおしてね。 //--> </script>
追記
さらにコンパクトに!てへぇっ!
var ToggleImage = function(d,w){ var c=0,t,o,m=0,g=[];while(o=arguments[2+m])(g[m++]=new Image).src=o; this.start = function(n){h(n)||(c=n),this.stop(c),t=setInterval((function(_){return function(){_.next()}})(this),w)}; this.next = function(n){c=h(n)?c+1:n,document.getElementById(d).setAttribute('src',g[c*=c<m].src)}; this.stop = function (n){h(n)||this.next(n);t&&clearInterval(t),t=0}; function h(n){return'undefined'===typeof n} };