I made a version of how it would work, in a very simple way (put in whole page):
var DH = $(document).height();
$(window).on('resize', function() {
DH = $(document).height();
})
$('.add').click(function() {
var topbarH = $('.topBar').height();
var footerH = $('.footer').height();
var exemploH = 0;
$('.exemplo').each(function(i) {
exemploH += +$(this).innerHeight() + parseFloat($(this).css('margin'));
})
if (exemploH <= DH - topbarH - footerH - 40) {
$('.container').append('<div class="exemplo">Aqui tem uma div</div>')
}
})
* {
margin: 0;
padding: 0;
border: 0;
box-sizing: border-box;
}
.container {
position: relative;
width: 100%;
height: calc(100vh - 120px);
top: 60px;
}
.exemplo {
width: 100%;
height: 20px;
margin: 10px 0;
background: #333;
color: #fff;
}
.topBar {
width: 100%;
height: 60px;
background: #ccc;
position: fixed;
top: 0;
}
.footer {
width: 100%;
height: 60px;
background: #ccc;
position: fixed;
bottom: 0;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div class="topBar">
<button class="add" style="padding: 10px">Adicionar</button>
</div>
<div class="container"></div>
<div class="footer"></div>
Only there is no element deletion when the page is resized.
If you do not want to block the creation can create the scroll bar, with overflow-y: auto
in the div.container
:
$('.add').click(function() {
$('.container').append('<div class="exemplo">Aqui tem uma div</div>')
})
* {
margin: 0;
padding: 0;
border: 0;
box-sizing: border-box;
}
.container {
position: relative;
width: 100%;
height: calc(100vh - 120px);
top: 60px;
overflow-y: auto;
}
.exemplo {
width: 100%;
height: 20px;
margin: 10px 0;
background: #333;
color: #fff;
}
.topBar {
width: 100%;
height: 60px;
background: #ccc;
position: fixed;
top: 0;
}
.footer {
width: 100%;
height: 60px;
background: #ccc;
position: fixed;
bottom: 0;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div class="topBar">
<button class="add" style="padding: 10px">Adicionar</button>
</div>
<div class="container"></div>
<div class="footer"></div>
Thanks for the code, but I can’t implement it because I’m using Visualforce, could you explain to me what you did and stuff so I can do something similar ? I’m new to jquery and I don’t quite understand what’s being done.
– Bruno
@Bruno, now I’m leaving and so I didn’t explain. But later I comment on the code. But the result, was as expected?
– Samir Braga
Ah right. In the basic was that, but I will add many inputs and the screen can not "block" the creation of them, but the overlapping part was just that. Vlw
– Bruno
@Bruno. The idea would be to create a scroll bar?
– Samir Braga
Yeah, that’s what I’m looking for.
– Bruno
I had not noticed that you had put another code, I will read this carefully because that is what I need, soon, any change return you the result. Thank you
– Bruno
I managed to use this in my application here. Thank you, that’s what I was looking for.
– Bruno