-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrotating-phrase.html
144 lines (136 loc) · 4.18 KB
/
rotating-phrase.html
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
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Rotating Phrase!</title>
<style>
body {
margin: 0;
}
h1.container-save-the-date {
text-align: center;
font-family: Graphik, sans-serif;
font-size: 25px;
font-weight: 400;
line-height: 1.52em;
padding: 0 32px;
max-width: 790px;
margin: 0 auto;
}
.title {
font-weight: 600;
font-size: 36px;
line-height: 1.1em;
letter-spacing: 0.01em;
margin-top: 0;
margin-bottom: 24px;
display: block;
}
/*ROTATING PHRASE*/
#rotating-phrase {
display: inline-block;
color: #5552ff;
transition: 0.25s all;
}
#rotating-phrase.hidden {
position: fixed;
left: 0;
top: 0;
transform: translate(-100%, -100%);
opacity: 0;
}
#rotating-phrase.opacity-0 {
opacity: 0;
}
@media (max-width: 992px) {
h1.container-save-the-date {
max-width: 500px;
}
}
@media (max-width: 768px) {
.title {
font-size: 32px;
margin-bottom: 16px;
}
}
@media (max-width: 640px) {
h1.container-save-the-date {
font-size: 17px;
max-width: 330px;
padding: 0 16px;
}
.title {
font-size: 24px;
}
}
</style>
</head>
<body>
<h1 class="container-save-the-date">
<span class="title">Enterprise Low-Code 2022</span>
<span id="rotating-phrase-container">
Discover what's new in the next-gen Software Development Platform that
helps
<span id="rotating-phrase">companies improve peoples lives.</span></span
>
</h1>
<script>
const words = [
"companies innovate.",
"companies evolve.",
"companies speed up.",
"developers do more.",
"companies improve peoples lives.",
];
(function () {
let rotatingPhrase = document.getElementById("rotating-phrase");
//Duplicate verb to know how much width the next word wll need
let hiddenVerb = rotatingPhrase.cloneNode(true);
hiddenVerb.classList.add("hidden");
setTimeout(function () {
//Set rotating-phrase initial width to make the widh transition later
let rotatingPhraseInitialWidth =
document.querySelector("#rotating-phrase:not(.hidden)")
.offsetWidth + 1;
document.querySelector("#rotating-phrase:not(.hidden)").style.width =
rotatingPhraseInitialWidth + "px";
}, 2000);
let rotatingPhraseContainer = document.getElementById(
"rotating-phrase-container"
);
rotatingPhraseContainer.insertBefore(hiddenVerb, rotatingPhrase);
let verbDisplayDuration = 2500;
let wordsQuantity = words.length;
let wordPosition = 0;
let changeWord = function (wordPosition) {
//first copy the next word to "hiddenVerb", to get the word width
hiddenVerb.innerHTML = words[wordPosition];
let newWordWidth = hiddenVerb.offsetWidth + 1;
rotatingPhrase.classList.add("opacity-0");
setTimeout(function () {
rotatingPhrase.innerHTML = "";
rotatingPhrase.style.width = newWordWidth + "px";
setTimeout(function () {
rotatingPhrase.innerHTML = words[wordPosition];
setTimeout(function () {
rotatingPhrase.classList.remove("opacity-0");
setTimeout(function () {
if (wordPosition >= wordsQuantity - 1) {
changeWord(0);
} else {
changeWord(wordPosition + 1);
}
}, verbDisplayDuration);
}, 250);
}, 250);
}, 250);
};
setTimeout(function () {
changeWord(0);
}, verbDisplayDuration);
})();
</script>
</body>
</html>