Skip to content

Commit 395582e

Browse files
committed
various updates
1 parent 6279cbb commit 395582e

File tree

7 files changed

+149
-173
lines changed

7 files changed

+149
-173
lines changed

assets/images/arrows.png

26.6 KB
Loading

assets/js/marquee.js

Lines changed: 19 additions & 97 deletions
Original file line numberDiff line numberDiff line change
@@ -1,100 +1,22 @@
1-
/*
2-
Vanilla Javascript Marquee
3-
Version: 0.2.1
4-
Author: Robert Bossaert <https://github.com/robertbossaert>
5-
Example call:
6-
7-
new Marquee('element');
8-
9-
new Marquee('element', {
10-
direction: 'rtl',
11-
});
12-
*/
13-
var Marquee = function (element, defaults) {
14-
var elem = document.getElementById(element),
15-
options = (defaults === undefined) ? {} : defaults,
16-
continuous = options.continuous || true, // once or continuous
17-
direction = options.direction || 'ltr', // ltr or rtl
18-
loops = options.loops || -1,
19-
speed = options.speed || 0.5,
20-
milestone = 0,
21-
marqueeElem = null,
22-
elemWidth = null,
23-
self = this,
24-
ltrCond = 0,
25-
loopCnt = 0,
26-
start = 0,
27-
textcolor = options.textcolor || '#000000', // Define the text color
28-
bgcolor = options.bgcolor || '#ffffff', // Define the background color
29-
opacity = options.opacity || 1.0,
30-
process = null,
31-
constructor = function (elem) {
32-
33-
// Build html
34-
var elemHTML = elem.innerHTML;
35-
var elemNode = elem.childNodes[1] || elem;
36-
elemWidth = elemNode.offsetWidth;
37-
marqueeElem = '<div>' + elemHTML + '</div>';
38-
elem.innerHTML = marqueeElem;
39-
marqueeElem = elem.getElementsByTagName('div')[0];
40-
elem.style.overflow = 'hidden';
41-
marqueeElem.style.whiteSpace = 'nowrap';
42-
marqueeElem.style.position = 'relative';
43-
marqueeElem.style.color = textcolor;
44-
marqueeElem.style.backgroundColor = bgcolor;
45-
marqueeElem.style.opacity = opacity;
46-
47-
if (continuous) {
48-
marqueeElem.innerHTML += elemHTML;
49-
marqueeElem.style.width = '200%';
50-
51-
if (direction === 'ltr') {
52-
start = -elemWidth;
53-
}
54-
} else {
55-
ltrCond = elem.offsetWidth;
56-
57-
if (direction === 'rtl') {
58-
milestone = ltrCond;
59-
}
60-
}
61-
62-
if (direction === 'ltr') {
63-
milestone = -elemWidth;
64-
} else if (direction === 'rtl') {
65-
speed = -speed;
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;
6614
}
67-
68-
self.start();
69-
70-
return marqueeElem;
71-
}
72-
73-
this.start = function () {
74-
process = window.setInterval(function () {
75-
self.play();
76-
});
77-
};
78-
79-
this.play = function () {
80-
// beginning
81-
marqueeElem.style.left = start + 'px';
82-
start = start + speed;
83-
84-
if (start > ltrCond || start < -elemWidth) {
85-
start = milestone;
86-
loopCnt++;
87-
88-
if (loops !== -1 && loopCnt >= loops) {
89-
marqueeElem.style.left = 0;
90-
}
91-
}
92-
}
93-
94-
this.end = function () {
95-
window.clearInterval(process);
15+
i = i + speed;
16+
}, 0);
9617
}
9718

98-
// Init plugin
99-
marqueeElem = constructor(elem);
100-
}
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))

footer.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -180,6 +180,7 @@
180180
</footer>
181181

182182
<script src="https://cdn.jsdelivr.net/npm/swiper@11/swiper-element-bundle.min.js"></script>
183+
<?php wp_footer(); ?>
183184
</body>
184185

185186
</html>

functions.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -144,13 +144,14 @@ function cjt_scripts()
144144
{
145145
wp_enqueue_style('cjt-style', get_stylesheet_uri(), array(), _S_VERSION);
146146

147-
wp_enqueue_script('cjt-navigation', get_template_directory_uri() . '/js/navigation.js', array(), _S_VERSION, true);
147+
wp_enqueue_script('cjt-navigation', get_template_directory_uri() . '/assets/js/navigation.js', array(), _S_VERSION, true);
148+
wp_enqueue_script('cjt-marquee', get_template_directory_uri() . '/assets/js/marquee.js', array(), _S_VERSION, true);
148149

149150
if (is_singular() && comments_open() && get_option('thread_comments')) {
150151
wp_enqueue_script('comment-reply');
151152
}
152153
}
153-
add_action('wp_enqueue_scripts', 'cjt_scripts');
154+
add_action('wp_enqueue_scripts', 'cjt_scripts', 1);
154155

155156
/**
156157
* Implement the Custom Header feature.

0 commit comments

Comments
 (0)