@@ -14,10 +14,12 @@ Anna is a lightning fast static site generator written in Go, designed for simpl
1414
1515<script >
1616const urls = [
17+ " https://adihegde.com" ,
1718 " https://hsp-ec.xyz" ,
1819 " https://anirudhsudhir.com" ,
19- " https://adihegde.com" ,
20- " https://polarhive.net"
20+ " https://adhesh.netlify.app" ,
21+ " https://polarhive.net" ,
22+ " https://sameermanvi.me"
2123];
2224
2325const gallery = document .getElementById (' embed-gallery' );
@@ -40,6 +42,99 @@ urls.forEach((url, index) => {
4042 item .appendChild (frame);
4143 gallery .appendChild (item);
4244});
45+
46+ // wrap the gallery in a scrollable marquee container if not already wrapped
47+ if (! gallery .parentElement .classList .contains (' marquee' )) {
48+ const marquee = document .createElement (' div' );
49+ marquee .className = ' marquee' ;
50+ gallery .parentNode .replaceChild (marquee, gallery);
51+ marquee .appendChild (gallery);
52+ gallery .classList .add (' marquee-track' );
53+ }
54+
55+ // setup auto-scroll + drag timeline
56+ function setupMarquee () {
57+ const container = gallery .parentElement ; // .marquee
58+ const track = gallery; // .marquee-track
59+ const initial = Array .from (track .children );
60+ if (! initial .length ) return ;
61+
62+ // duplicate items until track width >= 2x container width
63+ let totalWidth = initial .reduce ((sum , el ) => sum + el .getBoundingClientRect ().width + parseFloat (getComputedStyle (track).gap || 0 ), 0 );
64+ let i = 0 ;
65+ while (totalWidth < container .getBoundingClientRect ().width * 2 ) {
66+ const clone = initial[i % initial .length ].cloneNode (true );
67+ track .appendChild (clone);
68+ totalWidth += clone .getBoundingClientRect ().width + parseFloat (getComputedStyle (track).gap || 0 );
69+ i++ ;
70+ if (i > 60 ) break ;
71+ }
72+
73+ const trackWidth = Array .from (track .children ).reduce ((w , node ) => w + node .getBoundingClientRect ().width + parseFloat (getComputedStyle (track).gap || 0 ), 0 );
74+ const half = trackWidth / 2 ;
75+
76+ // auto-scroll state
77+ let last = null ;
78+ const speed = 12 ; // px/s
79+ let isPointerDown = false ;
80+ let isHover = false ;
81+ let isFocused = false ;
82+
83+ let startX = 0 ;
84+ let startScroll = 0 ;
85+
86+ container .addEventListener (' pointerdown' , (e ) => {
87+ isPointerDown = true ;
88+ container .setPointerCapture ? .(e .pointerId );
89+ startX = e .clientX ;
90+ startScroll = container .scrollLeft ;
91+ });
92+
93+ container .addEventListener (' pointermove' , (e ) => {
94+ if (! isPointerDown) return ;
95+ const dx = e .clientX - startX;
96+ container .scrollLeft = startScroll - dx;
97+ if (container .scrollLeft >= half) container .scrollLeft -= half;
98+ if (container .scrollLeft < 0 ) container .scrollLeft += half;
99+ });
100+
101+ container .addEventListener (' pointerup' , (e ) => {
102+ isPointerDown = false ;
103+ try { container .releasePointerCapture ? .(e .pointerId ); } catch (err) {}
104+ });
105+
106+ container .addEventListener (' pointercancel' , () => { isPointerDown = false ; });
107+ container .addEventListener (' mouseleave' , () => { isPointerDown = false ; });
108+
109+ container .addEventListener (' mouseenter' , () => { isHover = true ; });
110+ container .addEventListener (' mouseleave' , () => { isHover = false ; });
111+ container .addEventListener (' focusin' , () => { isFocused = true ; });
112+ container .addEventListener (' focusout' , () => { isFocused = false ; });
113+
114+ function step (t ) {
115+ if (! last) last = t;
116+ const dt = (t - last) / 1000 ;
117+ last = t;
118+
119+ if (! isPointerDown && ! isHover && ! isFocused) {
120+ container .scrollLeft += speed * dt;
121+ if (container .scrollLeft >= half) container .scrollLeft -= half;
122+ }
123+
124+ requestAnimationFrame (step);
125+ }
126+
127+ requestAnimationFrame (step);
128+
129+ // ensure initial scroll is positioned within first half
130+ container .scrollLeft = 0 ;
131+ }
132+
133+ window .addEventListener (' load' , setupMarquee);
134+ window .addEventListener (' resize' , () => {
135+ clearTimeout (window ._marqueeTimer );
136+ window ._marqueeTimer = setTimeout (setupMarquee, 150 );
137+ });
43138< / script>
44139
45140-- -
0 commit comments