gpt4 book ai didi

jquery - 无法将我已有的 div 添加两倍

转载 作者:行者123 更新时间:2023-11-28 00:06:45 26 4
gpt4 key购买 nike

好吧,我正在创建一个有趣的游戏。该游戏包含一个 5 秒计时器和形状像盒子的 div。第一轮你从 1 个 div 开始,目的是让你在计时器用完之前单击那个 div。如果你通过了,你会进入下一个级别,它会添加双倍的盒子,所以第 2 级你有 2 个盒子,第 3 级 4 个盒子,依此类推。我在创建总是双倍的 div 长度时遇到了麻烦。我没有太多代码,因为我尝试过的都没有用。这是 jsfiddle:

http://jsfiddle.net/JZdkQ/

<!doctype html>
<html>
<head>
<title>jQuery Project: An exploding game</title>
<meta charset="utf-8">
<style>
body, html {
width: 960;
height: 500%;
}
div.box {
position: relative;
width: 100px;
height: 100px;
background-color: orange;
}
div.exploding {
position: absolute;
width: 100px;
height: 100px;
background-color: red;
}
</style>


</head>
<body>
</body>
</html>

最佳答案

你的javascript...

setTimeout(function(){$("body").append("<div class='box'></div>").length() *2;}, 5000);

在说...

After 5 seconds get <body/> and append a <div class='box'/> to it, get the number of divs we just appended (i.e. 1) and multiply that number by 2 then discard the result.

使用这个...

setInterval(function(){$(".box").clone().appendTo("body");}, 5000);

它说...

Every 5 seconds, get all the elements of class box, make a copy of them, and append the copy to body.

http://jsfiddle.net/JZdkQ/2/

关于jquery - 无法将我已有的 div 添加两倍,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18110119/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com