-
Notifications
You must be signed in to change notification settings - Fork 0
/
rotating-word.html
132 lines (122 loc) · 3.71 KB
/
rotating-word.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
<!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 Word!</title>
<style>
body {
background-color: black;
}
.container-save-the-date {
text-align: center;
font-family: Graphik, sans-serif;
font-size: 32px;
color: #ffffff;
line-height: 1.3em;
}
@media (max-width: 480px) {
.container-save-the-date {
font-size: 26px;
text-align: left;
width: calc(100vw - 48px);
}
.container-save-the-date br {
display: none;
}
}
.save-the-date {
font-family: "Graphik Semibold", sans-serif;
font-size: 16px;
color: #dca9f1;
font-weight: 600;
}
.font-weight-600 {
font-weight: 600;
}
/*ROTATING TEXT*/
#rotating-verb {
display: inline-block;
color: #dca9f1;
transition: 0.25s all;
}
#rotating-verb.hidden {
position: fixed;
left: 0;
top: 0;
transform: translate(-100%, -100%);
opacity: 0;
}
#rotating-verb.opacity-0 {
opacity: 0;
}
</style>
</head>
<body>
<div class="container-save-the-date">
<span class="save-the-date">IT'S TODAY! </span>
<div>
<span class="font-weight-600">Enterprise Low Code 2021</span><br />
<span id="rotating-verb-container"
><span id="rotating-verb">Create</span> mission-critical software </span
><br />
that improves people's lives
</div>
</div>
<script>
const words = [
"Design",
"Maintain",
"Scale",
"Test",
"Secure",
"Dream",
"Deploy",
"Create",
];
(function () {
let rotatingVerb = document.getElementById("rotating-verb");
//Duplicate verb to know how much width the next word wll need
let hiddenVerb = rotatingVerb.cloneNode(true);
hiddenVerb.classList.add("hidden");
//Set rotating-verb initial width to make the widh transition later
let rotatingVerbInitialWidth = document.querySelector(
"#rotating-verb:not(.hidden)"
).offsetWidth;
document.querySelector("#rotating-verb:not(.hidden)").style.width =
rotatingVerbInitialWidth + "px";
let rotatingVerbContainer = document.getElementById(
"rotating-verb-container"
);
rotatingVerbContainer.insertBefore(hiddenVerb, rotatingVerb);
let verbDisplayDuration = 1500;
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;
rotatingVerb.classList.add("opacity-0");
setTimeout(function () {
rotatingVerb.style.width = newWordWidth + "px";
rotatingVerb.innerHTML = words[wordPosition];
setTimeout(function () {
rotatingVerb.classList.remove("opacity-0");
setTimeout(function () {
if (wordPosition >= wordsQuantity - 1) {
changeWord(0);
} else {
changeWord(wordPosition + 1);
}
}, verbDisplayDuration);
}, 250);
}, 250);
};
setTimeout(function () {
changeWord(0);
}, verbDisplayDuration);
})();
</script>
</body>
</html>