gpt4 book ai didi

javascript - 一个接一个地添加便签

转载 作者:行者123 更新时间:2023-11-28 15:17:40 24 4
gpt4 key购买 nike

在此先感谢,我正在尝试将粘性图像一个接一个地添加,如下图所示,但我得到的结果是一个在另一个下面。最新添加的便签应该在最上面,所有其他的便签都在最新的后面。任何帮助将不胜感激。

enter image description here

<!DOCTYPE html>
<html>
<head>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script>
<style>
.pink{
background:#f05f9d;
border:1px solid #f05f9d;
color:#fff;
font-weight:600;
}
.pink:hover{
background:#f05f9d;
border:1px solid #f05f9d;
color:#fff;
font-weight:600;
}
.pink-button{
padding: 10px 11px;
border-radius: 14px;
font-weight: 600;
font-size: 16px;
}
.sticky {
margin: 0;
padding: 8px 24px;
width:200px;
height:200px;
font-size: 1.4em;
border:1px #E8Ds47 solid;
-moz-box-shadow:0px 0px 6px 1px #333333;
-webkit-box-shadow:0px 0px 6px 1px #333333;
box-shadow:0px 0px 6px 1px #333333;
background: #fefdca;
background: -moz-linear-gradient(top, #fefdca 0%, #f7f381 100%);
background: -webkit-gradient(linear, left top, left bottom, color-stop(0%,#fefdca), color-stop(100%,#f7f381));
background: -webkit-linear-gradient(top, #fefdca 0%,#f7f381 100%);
background: -o-linear-gradient(top, #fefdca 0%,#f7f381 100%);
background: -ms-linear-gradient(top, #fefdca 0%,#f7f381 100%);
filter: progid:DXImageTransform.Microsoft.gradient( startColorstr='#fefdca', endColorstr='#f7f381',GradientType=0 );
background: linear-gradient(top, #fefdca 0%,#f7f381 100%);
}
.sticky p {
text-align: center;
}
.sticky textarea {
width:160px;
height:170px;
background: #fefdca;
background: -moz-linear-gradient(top, #fefdca 0%, #f7f381 100%);
background: -webkit-gradient(linear, left top, left bottom, color-stop(0%,#fefdca), color-stop(100%,#f7f381));
background: -webkit-linear-gradient(top, #fefdca 0%,#f7f381 100%);
background: -o-linear-gradient(top, #fefdca 0%,#f7f381 100%);
background: -ms-linear-gradient(top, #fefdca 0%,#f7f381 100%);
filter: progid:DXImageTransform.Microsoft.gradient( startColorstr='#fefdca', endColorstr='#f7f381',GradientType=0 );
background: linear-gradient(top, #fefdca 0%,#f7f381 100%);
border-bottom:none !important;
}
.sticky ol {
margin: 12px;
}
</style>
</head>
<body>
<div class="sticky">
<textarea placeholder="Type the problem here..."></textarea>
</div><br/>
<div id="spin_btn_div">
<div class="btn-container" style="margin-bottom:0px;position:absolute;margin-left:40px;">
<a class="btn pink pink-button shooter-btn" id="addProblem">Add problem</a>
</div>
</div>
</body>
<script>
$('#addProblem').click(function(){
$('.sticky').after('<div class="sticky"><textarea placeholder="Type the problem here..."></textarea><br></div>');
});
</script>
</html>

最佳答案

定位粘性并将其放入容器中。然后根据 .sticky 计数分配 left 值。检查下面的片段。

$('#addProblem').click(function() {
$('.sticky').after('<div class="sticky"><textarea placeholder="Type the problem here..."></textarea><br></div>');
var stickyCount = $('.sticky').length - 1;
$('.sticky').each(function() {
$(this).css('left', stickyCount * 100);
stickyCount--;
});
});
.pink {
background: #f05f9d;
border: 1px solid #f05f9d;
color: #fff;
font-weight: 600;
}

.pink:hover {
background: #f05f9d;
border: 1px solid #f05f9d;
color: #fff;
font-weight: 600;
}

.pink-button {
padding: 10px 11px;
border-radius: 14px;
font-weight: 600;
font-size: 16px;
}

.sticky {
margin: 0;
padding: 8px 24px;
width: 200px;
height: 200px;
font-size: 1.4em;
border: 1px #E8Ds47 solid;
-moz-box-shadow: 0px 0px 6px 1px #333333;
-webkit-box-shadow: 0px 0px 6px 1px #333333;
box-shadow: 0px 0px 6px 1px #333333;
background: #fefdca;
background: -moz-linear-gradient(top, #fefdca 0%, #f7f381 100%);
background: -webkit-gradient(linear, left top, left bottom, color-stop(0%, #fefdca), color-stop(100%, #f7f381));
background: -webkit-linear-gradient(top, #fefdca 0%, #f7f381 100%);
background: -o-linear-gradient(top, #fefdca 0%, #f7f381 100%);
background: -ms-linear-gradient(top, #fefdca 0%, #f7f381 100%);
filter: progid:DXImageTransform.Microsoft.gradient( startColorstr='#fefdca', endColorstr='#f7f381', GradientType=0);
background: linear-gradient(top, #fefdca 0%, #f7f381 100%);
}

.sticky p {
text-align: center;
}

.sticky textarea {
width: 160px;
height: 170px;
background: #fefdca;
background: -moz-linear-gradient(top, #fefdca 0%, #f7f381 100%);
background: -webkit-gradient(linear, left top, left bottom, color-stop(0%, #fefdca), color-stop(100%, #f7f381));
background: -webkit-linear-gradient(top, #fefdca 0%, #f7f381 100%);
background: -o-linear-gradient(top, #fefdca 0%, #f7f381 100%);
background: -ms-linear-gradient(top, #fefdca 0%, #f7f381 100%);
filter: progid:DXImageTransform.Microsoft.gradient( startColorstr='#fefdca', endColorstr='#f7f381', GradientType=0);
background: linear-gradient(top, #fefdca 0%, #f7f381 100%);
border-bottom: none !important;
}

.sticky ol {
margin: 12px;
}

.sticky-container {
position: relative;
min-height: 250px;
}

.sticky {
position: absolute;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script>
<div class="sticky-container">
<div class="sticky">
<textarea placeholder="Type the problem here..."></textarea>
</div>
</div><br/>
<div id="spin_btn_div">
<div class="btn-container">
<a class="btn pink pink-button shooter-btn" id="addProblem">Add problem</a>
</div>
</div>

关于javascript - 一个接一个地添加便签,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46807869/

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