@@ -60,6 +60,10 @@ function updateNavbarSize() {
6060
6161window . addEventListener ( 'scroll' , updateNavbarSize ) ;
6262
63+ window . addEventListener ( 'scroll' , function ( ) {
64+ document . getElementById ( "bg" ) . style . scale = 1 + ( window . scrollY / 2000 )
65+ } )
66+
6367updateNavbarSize ( ) ;
6468
6569function nav ( id ) {
@@ -154,12 +158,12 @@ function postPreview(html) {
154158
155159
156160function initData ( ) {
157-
158- fetch ( 'https://script.google.com/macros/s/AKfycbwuhE9ocPBrDPqiQ-eBUug3F1GUWxStrr7hawxaV3FBYIvwi7AmeMVnNvvVZELQzfZr/exec' )
161+ fetch ( 'https://script.google.com/macros/s/AKfycbwgAhOcLoOm7JnWpUutKZgqdied2S96IE4bbbI2HsXLUFOypi5S36lQ9V_l5rMwYBqh/exec' )
159162 . then ( res => res . json ( ) )
160163 . then ( data => {
161164 postData = data . columnA ;
162165 projectData = data . columnB ;
166+ bgData = data . columnC ;
163167
164168 document . getElementById ( "BlogPosts" ) . innerHTML = ``
165169 for ( let i = postData . length - 1 ; i >= 0 ; i -- ) {
@@ -171,6 +175,7 @@ function initData() {
171175 document . getElementById ( "ProjectPosts" ) . innerHTML += generatePostPreview ( 'projects' , JSON . parse ( projectData [ i ] ) , i )
172176 }
173177
178+ BGINIT ( ) ;
174179 load ( ) ;
175180 } )
176181 . catch ( error => {
@@ -191,6 +196,33 @@ function initData() {
191196 } )
192197}
193198
199+ function BGINIT ( ) {
200+ let rand1 = Math . floor ( Math . random ( ) * bgData . length ) ;
201+ let rand2 = Math . floor ( Math . random ( ) * bgData . length ) ;
202+ while ( rand2 === rand1 ) {
203+ rand2 = Math . floor ( Math . random ( ) * bgData . length ) ;
204+ }
205+
206+ document . getElementById ( 'bgimg1' ) . src = bgData [ rand1 ]
207+ document . getElementById ( 'bgimg2' ) . src = bgData [ rand2 ]
208+ setInterval ( changeBG , 10000 ) ;
209+ }
210+
211+ function changeBG ( ) {
212+ let rand = Math . floor ( Math . random ( ) * bgData . length ) ;
213+ while ( rand === document . getElementById ( 'bgimg2' ) . src ) {
214+ rand = Math . floor ( Math . random ( ) * bgData . length ) ;
215+ }
216+ document . getElementById ( 'bgimg1' ) . style . transition = '1s'
217+ document . getElementById ( 'bgimg1' ) . style . opacity = '0'
218+ setTimeout ( function ( ) {
219+ document . getElementById ( 'bgimg1' ) . src = document . getElementById ( 'bgimg2' ) . src ;
220+ document . getElementById ( 'bgimg2' ) . src = bgData [ Math . floor ( Math . random ( ) * bgData . length ) ]
221+ document . getElementById ( 'bgimg1' ) . style . transition = '0s'
222+ document . getElementById ( 'bgimg1' ) . style . opacity = '1'
223+ } , 500 )
224+ }
225+
194226function search ( input ) {
195227 let output = document . getElementById ( "SearchPosts" ) ;
196228 output . innerHTML = ``
@@ -227,75 +259,6 @@ function generatePostPreview(type, data, i) {
227259 <p>Posted on ${ data . date } </p><p>${ countWords ( data . body ) } words</p></div><div class="postPreviewParagraph">${ postPreview ( data . body ) } ...</div></div>`
228260}
229261
230- function LoadVFX ( ) {
231- const scss_to_compile = `
232- #snow {
233- position: fixed;
234- bottom: 0;
235- overflow: hidden;
236- height: 100vh;
237- width: 99vw;
238- }
239-
240- @function random_range($min, $max) {
241- $rand: random();
242- $random_range: $min + floor($rand * (($max - $min) + 1));
243- @return $random_range;
244- }
245-
246- .snow {
247- $total: 1000;
248- position: absolute;
249- width: 10px;
250- height: 10px;
251- background: white;
252- border-radius: 50%;
253-
254- @for $i from 1 through $total {
255- $random-x: random_range(0, 100vw);
256- $random-offset: random_range(-10, 10);
257- $random-x-end: $random-x + $random-offset;
258- $random-x-end-yoyo: $random-x + ($random-offset / 2);
259- $random-yoyo-time: random_range(30, 80) / 95;
260- $random-yoyo-y: $random-yoyo-time * 100vh;
261- $random-scale: random(10000) * 0.0001;
262- $fall-duration: random_range(10, 30) * 1s;
263- $fall-delay: random(30) * -1s;
264-
265- &:nth-child(#{$i}) {
266- opacity: random(10000) * 0.0001;
267- transform: translate($random-x, -10px) scale($random-scale);
268- animation: fall-#{$i} $fall-duration $fall-delay linear infinite;
269- }
270-
271- @keyframes fall-#{$i} {
272- #{percentage($random-yoyo-time)} {
273- transform: translate($random-x-end, $random-yoyo-y) scale($random-scale);
274- }
275-
276- to {
277- transform: translate($random-x-end-yoyo, 100vh) scale($random-scale);
278- }
279- }
280- }
281- }
282-
283-
284- ` ;
285-
286- Sass . compile ( scss_to_compile , ( result ) => {
287- var s = document . createElement ( "style" ) ;
288- s . innerHTML = result . text ;
289- document . body . append ( s ) ;
290- } ) ;
291-
292-
293- for ( let i = 0 ; i < 200 ; i ++ ) {
294- document . getElementById ( "snow" ) . innerHTML += `<div class="snow"></div>`
295- }
296-
297- }
298-
299262function getURLParameters ( ) {
300263 let currentUrl = window . location . href ;
301264
@@ -348,14 +311,15 @@ function load() {
348311 } else {
349312 nav ( 'home' ) ;
350313 }
351- document . getElementById ( "overlay" ) . style . display = `none`
352314
353- LoadVFX ( )
315+ setTimeout ( function ( ) {
316+ window . dispatchEvent ( new Event ( 'resize' ) ) ;
317+ } , 100 ) ;
318+
319+ document . getElementById ( "overlay" ) . style . display = `none`
354320} ;
355321
356- window . onload = function ( ) {
357- initData ( ) ;
358- }
322+ initData ( ) ;
359323
360324document . getElementById ( "overlay" ) . style . display = `flex`
361325document . getElementById ( "BlogPosts" ) . innerHTML = `<h2>Loading Posts...</h2>`
0 commit comments