中央に表示された<ooo>を左右に動かしたいのですが、右にしか動きません。
初歩的なミスかもしれませんが、よろしければ回答おねがいします。
<!DOCTYPE html> <html> <head> <style> div{ position:absolute; width: 60px; height:25px; color:green; top: 50px; } </style> <script> var ufo; function init(){ window.addEventListener("keydown",keydown); ufo = new UFO(document.getElementById("ufo"),100); } function keydown(e){ if (e.keCode == 37 ){ ufo.moveLeft(); } else if (e.keyCode == 39){ ufo.moveRight(); } } function UFO(_elem,_xpos){ this.elem =_elem; this.xpos =_xpos; this.moveLeft = function(){ this.xpos -= 10; this.elem.style.left = this.xpos + "px"; } this.moveRight = function(){ this.xpos += 10; this.elem.style.left = this.xpos + "px"; } this.elem.style.left = this.xpos + "px"; } </script> </head> <body onload="init()"> <div id="ufo"><(ooo)></div> </body> </html>
回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2019/07/15 07:11