Skip to content

Commit 078e3ae

Browse files
committed
fix news ticker scrolling
1 parent fa4a7d6 commit 078e3ae

2 files changed

Lines changed: 26 additions & 37 deletions

File tree

app/globals.css

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -143,6 +143,19 @@
143143
font-display: swap;
144144
}
145145

146+
@keyframes ticker {
147+
0% {
148+
transform: translateX(0);
149+
}
150+
100% {
151+
transform: translateX(-50%);
152+
}
153+
}
154+
155+
.animate-ticker {
156+
animation: ticker 75s linear infinite;
157+
}
158+
146159
@font-face {
147160
font-family: "General Sans";
148161
font-weight: 600;

components/NewsTicker/NewsTicker.tsx

Lines changed: 13 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -1,48 +1,24 @@
1-
"use client";
1+
import { useEffect, useRef, useState } from "react";
22

3-
import gsap from "gsap";
4-
import { useEffect, useRef } from "react";
3+
// Static mission statements
4+
const news = [
5+
"Welcome to LAP Docs, our mission is to provide you with the best possible tutorials that is easy to understand and follow. I hope you enjoy your stay with us and our tutorials actually help you learn something new.",
6+
"Our Motto: Simplicity in Tech",
7+
"Our Goal: Simplifying tech for everyone",
8+
];
59

610
export default function NewsTicker() {
7-
const tickerRef = useRef<HTMLDivElement | null>(null);
8-
9-
// Static mission statements
10-
const news = [
11-
"Welcome to LAP Docs, our mission is to provide you with the best possible tutorials that is easy to understand and follow. I hope you enjoy your stay with us and our tutorials actually help you learn something new.",
12-
"Our Motto: Simplicity in Tech",
13-
"Our Goal: Simplifying tech for everyone",
14-
];
15-
16-
useEffect(() => {
17-
const ticker = tickerRef.current;
18-
19-
if (ticker && news.length > 0) {
20-
const tickerWidth = ticker.scrollWidth / 2; // Half because we are duplicating items
21-
22-
gsap.to(ticker, {
23-
x: `-${tickerWidth}px`,
24-
duration: 75, // Faster duration for shorter text
25-
ease: "linear",
26-
repeat: -1,
27-
onRepeat: () => {
28-
gsap.set(ticker, { x: 0 });
29-
},
30-
});
31-
}
32-
}, [news]);
33-
3411
return (
3512
<div className="flex bg-[#8a2be2] text-white py-5 max-w-[95rem] w-full mx-auto relative overflow-hidden">
36-
<div className="bg-[#8a2be2] z-10 px-6">
13+
<div className="bg-[#8a2be2] z-10 px-6 absolute left-0 top-0 h-full flex items-center">
3714
<span className="flex gap-2 bg-[#8a2be2] font-semibold uppercase whitespace-nowrap">
3815
<p>MISSION:</p>
39-
<p className="block sm:hidden">+++</p>
4016
</span>
4117
</div>
4218
{/* News ticker container */}
43-
<div className="relative flex overflow-hidden w-full">
44-
<div ref={tickerRef} className="flex gap-4 whitespace-nowrap">
45-
{/* First set - visible to screen readers and crawlers */}
19+
<div className="relative flex overflow-hidden w-full pl-32 sm:pl-40">
20+
<div className="flex gap-4 whitespace-nowrap animate-ticker w-fit">
21+
{/* First set - visible to screen readers */}
4622
{news.map((newsItem, index) => (
4723
<div
4824
key={`original-${index}`}
@@ -51,8 +27,8 @@ export default function NewsTicker() {
5127
<p>{newsItem} +++</p>
5228
</div>
5329
))}
54-
{/* Duplicated sets for animation - hidden from assistive tech */}
55-
{[...news, ...news, ...news].map((newsItem, index) => (
30+
{/* Duplicate set for seamless looping */}
31+
{news.map((newsItem, index) => (
5632
<div
5733
key={`duplicate-${index}`}
5834
className="text-white text-lg font-normal"

0 commit comments

Comments
 (0)