所以,我做了一个cookie点击器,我希望我的升级放在我的cookie旁边,它是居中的。我如何让我的升级放在左边,并让cookie仍然居中?如果我可以的话,它会看起来更好。如果你有任何想法,请,请尽快回复。
帮助将不胜感激!:^)
<script>
function update() {
document.getElementById('text').value = cookiecount;
document.title = cookiecount + " Cookies";
document.getElementById('ammountMultiplier').innerHTML = "Multiplier Upgrade x" + (multiplier+1);
document.getElementById('ammountMultiplier2').innerHTML = "x" + (multiplier+1);
document.getElementById('costMultiplier').innerHTML = ((multiplier+1) * 100) + " Cookies";
document.getElementById('currentMultiplier').innerHTML = "Your current Multiplier is x" + (multiplier);
document.getElementById('ammountAutoClick').innerHTML = "You Own " + autoClick + " Auto Clickers";
document.getElementById('costAutoClick').innerHTML = ((autoClick+1) * 12) + " Cookies";
document.getElementById('ammountFarms').innerHTML = "You Own " + farms + " Farms";
document.getElementById('costFarms').innerHTML = ((farms+1) * 15) + " Cookies";
document.getElementById('ammountGrandma').innerHTML = "You Own " + grandma +" Grandmas";
document.getElementById('costGrandma').innerHTML = ((grandma+1) * 15) + "Cookies";
document.getElementById('cookiespersecond').innerHTML = "You are gaining " + (((autoClick)+(farms*2)+(grandma*2))*multiplier) + " Cookies per/s";
}
var multiplier = 1;
var cookiecount = 0;
var autoClick = 0;
var farms = 0;
var grandma = 0;
function timer() {
cookiecount = cookiecount + autoClick*multiplier;
cookiecount = cookiecount + farms*2*multiplier;
cookiecount = cookiecount + grandma*2*multiplier;
update()
}
setInterval(timer, 1000)
</script>
<html>
<style>
body{
background-image: url('http://pa1.narvii.com/6718/86e6473ccdc4cfefcb427d96def5cf6917d481f4_00.gif');
background-size: cover;
}
</style>
<center>
<head><title>0 Cookies</title></head>
<body>
<p id="cookiespersecond">You are gaining 0 Cookies per/s</p>
<a href=# onclick="add()"><img src="cookie.jpg"></a>
<br><br>
You got:
<input type="text" id="text" disabled style= text-align:center value=0>
<script>
function add() {
cookiecount = cookiecount + 1
update()
}
</script>
Cookies
<br><br></center>
<button><a href="#" onClick="save()">Save</a></button>
<button><a href="#" onclick="load()">Load</a></button>
<br><br>
<p id="ammountMultiplier">Multiplier Upgrade x2</p>
<button><a href="#" onClick="buyMultiplier()"><span id="ammountMultiplier2">x2</span></a></button>
<p id="costMultiplier">200 Cookies</p>
<p id="currentMultiplier">Your current Multiplier is x1</p>
<br>
<p>Buy 1 Auto Clicker</p>
<button><a href="#" onClick="buyAutoClick()"><img src=mouse.jpg width="30px" height="40px"></a></button>
<p id="costAutoClick">12 Cookies</p>
<p id="ammountAutoClick">You Own 0 Auto Clickers</p>
<br>
<p>Buy 1 Farm</p>
<button><a href="#" onClick="buyFarm()"><img src="farm.jpg" width="50px" height="50px"></a></button>
<p id="costFarms">15 Cookies</p>
<p id="ammountFarms">You Own 0 Farms</p>
<br>
<p>Buy 1 Grandma</p>
<button><a href="#" onClick="buyGrandma()"><img src="grandma.jpg" width="50px" height="50px"></a></button>
<p id="costGrandma">15 Cookies</p>
<p id="ammountGrandma">You own 0 Grandmas</p>
<script>
function save() {
localStorage.setItem("cookiecount", cookiecount);
localStorage.setItem("autoClick", autoClick);
localStorage.setItem("farms", farms);
localStorage.setItem("multiplier", multiplier);
}
function load() {
cookiecount = localStorage.getItem("cookiecount");
cookiecount = parseInt(cookiecount);
autoClick = localStorage.getItem("autoClick");
autoClick = parseInt(autoClick);
farms = localStorage.getItem("farms");
farms = parseInt(farms);
multiplier = localStorage.getItem("multiplier");
multiplier = parseInt(multiplier);
update()
}
function buyAutoClick() {
if (cookiecount >= ((autoClick+1) * 12)) {
cookiecount = cookiecount - ((autoClick+1) * 12);
autoClick = autoClick + 1;
update()
}
}
function buyFarm() {
if (cookiecount >= ((farms+1) * 15)) {
cookiecount = cookiecount - ((farms+1) * 15);
farms = farms + 1;
update()
}
}
function buyMultiplier() {
if (cookiecount >= ((multiplier+1) * 100)) {
cookiecount = cookiecount - ((multiplier+1) * 50);
multiplier = multiplier + 1;
update()
}
}
function buyGrandma() {
if (cookiecount >= ((grandma+1) * 15)) {
cookiecount = cookiecount - ((grandma+1) * 15);
grandma = grandma + 1;
update()
}
}
</script>
</html>
救命啊!
1条答案
按热度按时间5cnsuln71#
你可以尝试将你用JS创建的HTML元素分成两类:cookie-side和upgrades/buildings,并将它们放入它们自己的div标签中,这些标签将被保存在另一个div中,类为game-wrapper标签,你可以在CSS中添加以下代码: