-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmarquee-text.css
125 lines (108 loc) · 3.23 KB
/
marquee-text.css
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
/* Inserir um texto com efeito de letreiro */
/* Colar o texto abaixo em Avançado => Atributos (* requer Elementor Pro*) do conteiner: */
data-marquee|Seu texto aqui •
/* ======================================================================= */
/* Colar o código Javascript abaixo em um widget HTML dentro do conteiner: */
<script>
const getMarqueeNode = content => {
const el = document.createElement('div');
el.setAttribute('data-marquee-style', true);
el.textContent = content
return el;
}
class Marquee {
constructor(el){
this.el = el;
this.content = el.getAttribute('data-marquee')
this.render();
}
render(){
// create the shadow element to measure and calculate
// the amount of animated items required for marquee
// create
const shadow = getMarqueeNode(this.content);
shadow.setAttribute('data-marquee-shadow', true);
// add shadow element to sanitized DOM
this.el.innerHTML = "";
this.el.appendChild(shadow);
// calculate how many visible items are needed
const inView = this.calculateItemsInView(shadow);
// create container to house animated visible items
const overflow = document.createElement('div');
overflow.setAttribute('data-marquee-overflow', true);
const content = document.createElement('div');
content.setAttribute('data-marquee-container', true);
// put the content container into an overflow: hidden wrapper
overflow.appendChild(content);
// double the amount to fill the screen to animate loop
const count = inView * 3;
// populate with children
for( var i = 0; i < count; i++) {
content.appendChild(getMarqueeNode(this.content))
}
// add to DOM
this.el.appendChild(overflow);
// debug
// console.log("visible items required", inView);
// console.log("total items required", count);
}
calculateItemsInView(ref){
const [single, total] = [ref.clientWidth, ref.parentNode.clientWidth];
// ceil in order to ensure there's never a shortage
return Math.floor(total / single) + 1;
}
}
// find elements and create Marquee instances
const nodes = document.querySelectorAll('[data-marquee]')
const arr = Array.from(nodes);
const refs = (arr || []).map( node => new Marquee(node) );
// recalculate on resize
window.addEventListener( 'resize', () => refs.map( r => r.render() ) );
</script>
/* ================================================================ */
/* Colar o CSS abaixo em Configurações da página => Custom CSS: */
@-webkit-keyframes marquee {
100% {
transform: translateX(-100%);
}
}
@keyframes marquee {
100% {
transform: translateX(-100%);
}
}
[data-marquee] {
--loop-duration: 30s;
display: block;
}
[data-marquee] [data-marquee-shadow] {
position: absolute;
visibility: hidden;
height: auto;
width: auto;
white-space: nowrap;
}
[data-marquee] [data-marquee-overflow] {
overflow: hidden;
transform: translate3d(0, 0, 0);
}
[data-marquee] [data-marquee-container] {
display: flex;
-webkit-animation: marquee var(--loop-duration) linear infinite;
animation: marquee var(--loop-duration) linear infinite;
}
[data-marquee] [data-marquee-style] {
flex: 0 0 auto;
display: flex;
align-items: center;
justify-content: center;
}
[data-marquee-style] {
padding: 1.5em 0.3em;
display: flex;
color: #000000;
font-size: 1em;
font-weight: 700;
letter-spacing: 0.3em;
text-transform: uppercase;
}