Here's the thing:
- got multiple divs which are on
window.onload
hidden via CSS - upon
window.onload
JS in set intervals make random div shown for some amount of time - every time some of these random divs becomes shown it pushes other divs (which are always shown) down below and when it becomes hidden it will push the other divs of
class .wanna-stay-where-I-am
back on original position - I tried to apply for both classes combinations of properties:
position:relative
,white-space: pre-wrap;
,overflow:hidden
or even wrap those to superordinal divs with fixed heigth, f.e. 50 to 50 %, but still can't figure this out for life..
var todo = null;
var div_number;
var used_numbers;
window.onload = (event) => {
div_number = 1;
used_numbers = new Array();
if (todo == null) {
todo = setInterval(showQuotes, 3000);
}
}
function showQuotes() {
used_numbers.splice(0, used_numbers.length);
$('.bad-pusher').hide();
for (var inc = 0; inc < div_number; inc++) {
var random = get_random_number();
$('.bad-pusher:eq(' + random + ')').show();
}
$('.bad-pusher').delay(4000).fadeOut(1000);
}
function get_random_number() {
var number = randomFromTo(0, 100);
if ($.inArray(number, used_numbers) != -1) {
return get_random_number();
} else {
used_numbers.push(number);
return number;
}
}
function randomFromTo(from, to) {
return Math.floor(Math.random() * (to - from + 1) + from);
}
.bad-pusher {
float:left;
font-size:17px;
max-width: max-content;
max-height: content;
border:1px solid #6A6A6A;
color:#6A6A6A;
margin:0.3%;
padding:0px 10px;
transition: 0.2s;
display: none;
white-space: pre-wrap;
}
.wanna-stay-where-I-am {
float:left;
font-size:30px;
font-weight: 200;
max-width: content;
max-height: content;
border:1px solid #0074FF;
color:#0074FF;
margin:.3%;
padding:2px 10px;
transition: 0.2s;
}
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<div id="1" class="bad-pusher">I am pushing others down</div>
<div id="100" class="bad-pusher">I am pushing others down</div>
<div class="wanna-stay-where-I-am">Hey stop pushing me down</div>
QUESTION: How to amend the code so the class .bad-pusher
won't have any positioning impacts on class .wanna-stay-where-I-am
and so the content on page will remain fixed even on .show()
and .hide()
changes which are underway on page load via JS.
Sorry if that's messy, tried to clarify that the best I can. Anyone?