-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathscript.js
96 lines (84 loc) · 2.87 KB
/
script.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
$(function(){
/* All mobile devices */
if ($(window).width() < 992) {
$('nav').removeClass('sticky-top')
}
/* Large devices (laptops/desktops, 992px and up) */
else {
$('nav').addClass('sticky-top')
}
$("form").on("submit", function(event) {
var formData = {
name: $("#inputName").val(),
email: $("#inputEmail").val(),
message: $("#inputMessage").val(),
};
// stop page from refreshing on submit click.
event.preventDefault();
$.ajax({
type: "POST",
url: "https://appnaca.org:1000",
data: formData,
dataType: "json",
encode: true,
timeout: 5000,
beforeSend: function() {
$('#spinner').removeClass('hidden')
}
})
.done(function(data) {
$("#contactSubmitMsg").html('<span style="color:white;background-color: #006600; padding: 0.5rem;border-radius: 10px">' + data.message + '</span');
$('#spinner').addClass('hidden')
})
.fail(function (data) {
$("#contactSubmitMsg").html('<span style="color:red">Sorry cant connect to the server. Please try again later.</span');
})
});
});
/* Typewriter effect */
// set up text to print, each item in array is new line
var aText = new Array(
"Strengthening cross-community collaboration",
"to support community services & initiatives"
);
var iSpeed = 100; // time delay of print out
var iIndex = 0; // start printing array at this posision
var iArrLength = aText[0].length; // the length of the text array
var iScrollAt = 20; // start scrolling up at this many lines
var iTextPos = 0; // initialise text position
var sContents = ''; // initialise contents variable
var iRow; // initialise current row
function typewriter()
{
sContents = ' ';
iRow = Math.max(0, iIndex-iScrollAt);
var destination = document.getElementById("typedtext");
while ( iRow < iIndex ) {
sContents += aText[iRow++] + '<br />';
}
destination.innerHTML = sContents + aText[iIndex].substring(0, iTextPos) + "_";
if ( iTextPos++ == iArrLength ) {
iTextPos = 0;
iIndex++;
if ( iIndex != aText.length ) {
iArrLength = aText[iIndex].length;
setTimeout("typewriter()", 500);
}
} else {
setTimeout("typewriter()", iSpeed);
}
}
/* Scrolling animations */
const observer = new IntersectionObserver((entries) => {
entries.forEach((entry) => {
console.log(entry.target.id)
if (entry.isIntersecting) {
entry.target.classList.add('show');
if (entry.target.id === 'typedtext') {
typewriter();
}
}
});
})
const hiddenElements = document.querySelectorAll('.hide');
hiddenElements.forEach((el) => observer.observe(el));