<script> function Counter(img, sw, sh) { this.Img= img; //Image File(0~9の画像) this.Sw = sw; //Sprite の幅 this.Sh = sh; //Sprite の高さ //「上, 右, 下, 左」の順 this.View = function() { var s1= 'style="clip:rect(0px,' + (this.Sw*10) + 'px,' + this.Sh + 'px,0px);'; var s2 = 'position:absolute;left:20px;top:100px;'; var s = '<img src="' + this.Img + '"' + s1 + s2 + '">'; document.write(s); } //「上, 右, 下, 左」の順 this.View_Num = function(num, x, y) { var pos = num*this.Sw; var s1= 'style="clip:rect(0px,' + (pos+this.Sw) + 'px,' + this.Sh + 'px,' + pos + 'px);'; var s2 = 'position:absolute;left:' + (x-pos) + 'px;top:' + y + 'px;'; var s = '<img src="' + this.Img + '"' + s1 + s2 + '">'; document.write(s); } } </script> </head> |
【実行画面】<br> <script> var cls = new Counter("img/nums.gif", 8, 10); cls.View(); cls.View_Num(0, 70, 140); cls.View_Num(1, 78, 140); cls.View_Num(2, 86, 140); cls.View_Num(5, 100, 160); cls.View_Num(4, 106, 160); cls.View_Num(0, 112, 160); cls.View_Num(0, 118, 160); </script> |
<script> function Counter(img, sw, sh) { this.Img= img; //Image File(0~9の画像) this.Sw = sw; //Sprite の幅 this.Sh = sh; //Sprite の高さ |
this.View = function() { var s1= 'style="clip:rect(0px,' + (this.Sw*10) + 'px,' + this.Sh + 'px,0px);'; var s2 = 'position:absolute;left:20px;top:100px;'; var s = '<img src="' + this.Img + '"' + s1 + s2 + '">'; document.write(s); } |
//「上, 右, 下, 左」の順 this.View_Num = function(num, x, y) { var pos = num*this.Sw; var s1= 'style="clip:rect(0px,' + (pos+this.Sw) + 'px,' + this.Sh + 'px,' + pos + 'px);'; var s2 = 'position:absolute;left:' + (x-pos) + 'px;top:' + y + 'px;'; var s = '<img src="' + this.Img + '"' + s1 + s2 + '">'; document.write(s); } |