|
1 |
| - function Marquee(selector, speed) { |
2 |
| - const parentSelector = document.querySelector(selector); |
3 |
| - const clone = parentSelector.innerHTML; |
4 |
| - const firstElement = parentSelector.children[0]; |
5 |
| - let i = 0; |
6 |
| - console.log(firstElement); |
7 |
| - parentSelector.insertAdjacentHTML('beforeend', clone); |
8 |
| - parentSelector.insertAdjacentHTML('beforeend', clone); |
9 |
| - |
10 |
| - setInterval(function () { |
11 |
| - firstElement.style.marginLeft = `-${i}px`; |
12 |
| - if (i > firstElement.clientWidth) { |
13 |
| - i = 0; |
14 |
| - } |
15 |
| - i = i + speed; |
16 |
| - }, 0); |
17 |
| - } |
18 |
| - |
19 |
| - //after window is completed load |
20 |
| - //1 class selector for marquee |
21 |
| - //2 marquee speed 0.2 |
22 |
| - window.addEventListener('load', Marquee('[data-trusted-brands]', 0.5)) |
| 1 | + function Marquee(selector, speed) { |
| 2 | + const parentSelector = document.querySelector( selector ); |
| 3 | + |
| 4 | + if (!parentSelector) return |
| 5 | + const clone = parentSelector.innerHTML; |
| 6 | + const firstElement = parentSelector.children[0]; |
| 7 | + let i = 0; |
| 8 | + console.log(firstElement); |
| 9 | + parentSelector.insertAdjacentHTML('beforeend', clone); |
| 10 | + parentSelector.insertAdjacentHTML('beforeend', clone); |
| 11 | + |
| 12 | + setInterval(function () { |
| 13 | + firstElement.style.marginLeft = `-${i}px`; |
| 14 | + if (i > firstElement.clientWidth) { |
| 15 | + i = 0; |
| 16 | + } |
| 17 | + i = i + speed; |
| 18 | + }, 0); |
| 19 | + } |
| 20 | + |
| 21 | + //after window is completed load |
| 22 | + //1 class selector for marquee |
| 23 | + //2 marquee speed 0.2 |
| 24 | + window.addEventListener('load', Marquee('[data-trusted-brands]', 0.5)) |
0 commit comments