在此先感谢,我正在尝试一个接一个地添加粘性图像,如下图所示,但我得到的结果是另一个。最新添加的便利贴应该在最前面,所有其他注释都应该在最新的后面。任何帮助都会受到启发。
<!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>
&#13;
答案 0 :(得分:1)
定位粘性并将其放入容器中。然后根据left
计数分配.sticky
值。请查看下面的代码段。
$('#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>
答案 1 :(得分:0)
这是我的版本
HTML:
<section class="sticky-wrapper">
<div class="sticky">
<textarea placeholder="Type the problem here..."></textarea>
</div>
</section>
<br/>
<div id="spin_btn_div">
<div class="btn-container">
<a class="btn pink pink-button shooter-btn" id="addProblem">Add problem</a>
</div>
CSS
.sticky-wrapper {
position: relative;
min-height: 300px;
}
.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 {
position: absolute;
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;
}
JavaScript的:
var zIndex = 0;
var currentXPosition = 0;
$('#addProblem').click(function(){
zIndex++;
$('.sticky-wrapper').append('<div class="sticky" style="z-index: ' + zIndex +'; left: 0px"><textarea placeholder="Type the problem here..."></textarea><br></div>');
$(".sticky-wrapper").find(".sticky:not(:last-child)").each(function (i, item) {
var itemLeftPos = parseInt(item.style.left || 0);
currentXPosition = 100;
item.style.left = (itemLeftPos + currentXPosition) + "px";
});
});
注意:我已经添加了类.sticky-wrapper
的包装元素。
Link to JSFiddle