I want this to run but so that it doesn’t for 5 seconds after the page fully loads. How would I go about achieving this, I believe its a ,500
somewhere but I am not sure where this would go.
If you have any questions please ask!
Thank you in advance for you help on this matter, its very much appreciated!
JavaScript
x
48
48
1
$(".demoBookedContentClose").click(function(){
2
$("body").addClass("demoBookedHidden");
3
});
4
5
6
function shuffle(array) {
7
var currentIndex = array.length,
8
temporaryValue, randomIndex;
9
10
// While there remain elements to shuffle...
11
while (0 !== currentIndex) {
12
13
// Pick a remaining element...
14
randomIndex = Math.floor(Math.random() * currentIndex);
15
currentIndex -= 1;
16
17
// And swap it with the current element.
18
temporaryValue = array[currentIndex];
19
array[currentIndex] = array[randomIndex];
20
array[randomIndex] = temporaryValue;
21
}
22
23
return array;
24
}
25
26
var queue = [];
27
28
29
30
function setUp() {
31
var elems = $(".demoBooked").get();
32
queue = shuffle(elems);
33
showNext();
34
}
35
36
function showNext() {
37
var elem = queue.pop();
38
if (elem) {
39
$(elem)
40
.fadeIn(2000)
41
.delay(5000)
42
.fadeOut(1000, function(){ setTimeout(showNext,25000); });
43
} else {
44
setUp();
45
}
46
}
47
48
setUp();
JavaScript
1
54
54
1
.demoBooked {
2
background: #fff;
3
box-shadow: 0 1px 2px rgba(0,0,0,0.05), 0 2px 4px rgba(0,0,0,0.08);
4
border: 1px solid #dddddd;
5
padding: 20px;
6
border-radius: 8px;
7
display: none;
8
}
9
.demo-booked-section {
10
position: fixed;
11
bottom: 10px;
12
left: 10px;
13
z-index: 2;
14
}
15
.demoBooked h3 {
16
font-size: 22px;
17
font-weight: 900;
18
margin-bottom: 4px;
19
}
20
.demoBooked img {
21
max-width: 50px;
22
margin-top: -55px;
23
border-radius: 100%;
24
display: inline-block;
25
}
26
.demoBookedContent {
27
display: inline-block;
28
padding-left: 20px;
29
}
30
.demoBooked p {
31
font-size: 18px;
32
line-height: 20px;
33
}
34
.demoBookedTime {
35
color: #e12826;
36
}
37
.demoBookedContentClose {
38
position: absolute;
39
right: 15px;
40
top: 10px;
41
font-size: 10px;
42
cursor: pointer;
43
}
44
.demoBookedHidden .demo-booked-section {
45
display: none!important;
46
}
47
.demoBookedTime {
48
font-size: 15px;
49
}
50
@media only screen and (max-width: 768px) {
51
.demo-booked-section {
52
display: none!important;
53
}
54
}
JavaScript
1
22
22
1
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
2
3
<div class="demo-booked-section">
4
<div class="demoBooked">
5
<img src="/wp-content/uploads/2021/01/william-diaz.jpg">
6
<div class="demoBookedContent">
7
<span class="demoBookedContentClose">X</span>
8
<h3>William Diaz</h3>
9
<p class="demoBookedText">Just started a FREE trial</p>
10
<p class="demoBookedTime">1hrs ago</p>
11
</div>
12
</div>
13
<div class="demoBooked">
14
<img src="/wp-content/uploads/2021/01/freya-smith.jpg">
15
<div class="demoBookedContent">
16
<span class="demoBookedContentClose">X</span>
17
<h3>Freya Smith</h3>
18
<p class="demoBookedText">Just started a FREE trial</p>
19
<p class="demoBookedTime">3hrs ago</p>
20
</div>
21
</div>
22
</div>
Advertisement
Answer
Since you want the function to be fired up 5 seconds after the page is fully loaded you will be using a combination of two functions.
I see you are using jQuery in your website The below code waits until the page is fully loaded then fires up the code inside the brackets.
JavaScript
1
4
1
$( document ).ready(function() {
2
// code here
3
});
4
So inside the above code you will add your 5 seconds waiting function
JavaScript
1
4
1
setTimeout(function(){
2
// Magic happens here
3
},5000);
4
The final code is
JavaScript
1
6
1
$( document ).ready(function() {
2
setTimeout(function(){
3
// Magic happens here
4
},5000);
5
});
6