var ele = 新しいオブジェクト; ele = { div : document.createElement("div"), span: function (){ var sp = document.createElement("span"); for(var s in boxBaseAttr) { sp.style[s] = boxBaseAttr[s]; } sp.setAttribute("タイプ", "良い"); リターンsp; }, badspan : function (){ var sp2 = document.createElement("span"); for(var s in boxBaseAttr2) { sp2.style[s] = boxBaseAttr2[s]; } sp2.setAttribute("type", "bad"); sp2 を返します; } };
var sco = 0、lifeWidth = 690、lifes = true; var bar = { getScore : function () { sco = 10; $("sc").innerHTML = sco; }, loseScore : function (){ sco -= 10; $("sc").innerHTML = sco; }, life : function (){ var life = $("life"); var sl = setInterval(function(){ if(lifeWidth < 23) { lifes = false; clearInterval(sl); return; } else { lifeWidth -= 23; life.style.width = lifeWidth "px" } },1000); } }; var fire = { init : function (o, x, y) { o.style.display = "ブロック"; o.style.left = x "px"; o.style.top = y "px"; var fs = setInterval(function(){ if (y >= 280) { y -= 10; o.style.top = y "px"; } else{ clearInterval(fs); o.style.display = "none" } },10); } };
/*-- ゲーム開始 --*/ function game() { var content = $("content"), x = 0; var pigBaseAttr = 新しいオブジェクト; pigBaseAttr = { background : "url(bike.gif) no-repeat center top", position : "absolute", top : content.clientHeight-44 "px", left : (content.clientWidth - 45)/2 "px", width : "45px", height : "44px", zIndex : 1000 }; var pig = ele.div.cloneNode(true); for(var s in pigBaseAttr) { pig.style[s] = pigBaseAttr[s]; } content.appendChild(pig);