Browse Source

front cover opening

master
farhan 5 months ago
parent
commit
b80dfee895
3 changed files with 128 additions and 131 deletions
  1. 30
    0
      resources/css/app.css
  2. 98
    12
      resources/js/app.js
  3. 0
    119
      resources/views/digital-card.blade.php

+ 30
- 0
resources/css/app.css View File

@@ -31,4 +31,34 @@
31 31
 /* Remove outline on focus for all elements */
32 32
 *:focus {
33 33
     outline: none;
34
+}
35
+
36
+html {
37
+    scroll-behavior: smooth;
38
+}
39
+body.no-scroll {
40
+    overflow: hidden;
41
+}
42
+.fade-element {
43
+    opacity: 0;
44
+    transition: opacity 3s ease-in-out;
45
+}
46
+.fade-in {
47
+    opacity: 1;
48
+}
49
+.petal-overlay {
50
+    position: fixed; /* Fixes the position to the viewport */
51
+    top: 0;
52
+    left: 0;
53
+    width: 100vw;
54
+    height: 100vh;
55
+    pointer-events: none; /* Allows interactions through the overlay */
56
+    z-index: 9999; /* Ensures it is on top of other elements */
57
+    opacity: 0.3; /* Set the opacity to a lower value */
58
+    display: none; /* Initially hidden */
59
+}
60
+.petal-overlay img {
61
+    width: 100%;
62
+    height: 100%;
63
+    object-fit: cover; /* Ensures the image covers the entire container */
34 64
 }

+ 98
- 12
resources/js/app.js View File

@@ -81,20 +81,106 @@ $(function() {
81 81
     // Initially check visibility on page load
82 82
     $(window).trigger('scroll');
83 83
 
84
-    document.addEventListener('DOMContentLoaded', function() {
85
-        const observer = new IntersectionObserver(entries => {
86
-            entries.forEach(entry => {
87
-                if (entry.isIntersecting) {
88
-                    entry.target.classList.add('animate-fadeUp');
89
-                    entry.target.classList.remove('opacity-0');
84
+    
85
+});
86
+
87
+document.addEventListener('click', function () {
88
+    setTimeout(function () {
89
+        document.getElementById('petalOverlay').style.display = 'block';
90
+    }, 1000); // Delay of 1 second (1000 milliseconds)
91
+});
92
+
93
+document.addEventListener('DOMContentLoaded', function() {
94
+    var audioElement = document.getElementById('player');
95
+    var hasPlayed = false; // To ensure audio only plays once upon clicking and scrolling
96
+    var scrollCount = 0;
97
+    var maxScrolls = 8;
98
+    var scrollInterval = 500; // Time in milliseconds between each scroll
99
+    var scrollAmount = window.innerHeight / 6; // Amount to scroll per interval
100
+
101
+    function playAudio() {
102
+        if (!hasPlayed) {
103
+            console.log('play')
104
+            var playPromise = audioElement.play();
105
+
106
+            if (playPromise !== undefined) {
107
+                playPromise.then(function() {
108
+                    // Automatic playback started!
109
+                    hasPlayed = true; // Prevent further attempts to play
110
+                }).catch(function(error) {
111
+                    // Automatic playback failed.
112
+                    console.log('Autoplay failed: ' + error);
113
+                });
114
+            }
115
+        }
116
+    }
117
+
118
+    function smoothScroll() {
119
+        if (!hasPlayed) {
120
+            playAudio();
121
+            scrollCount++;
122
+            if (scrollCount >= maxScrolls) {
123
+                playAudio();
124
+            } else {
125
+                var start = window.pageYOffset;
126
+                var target = start + scrollAmount;
127
+                var duration = 1500; // duration of the animation
128
+                var startTime = null;
129
+
130
+                function scrollStep(timestamp) {
131
+                    if (!startTime) startTime = timestamp;
132
+                    var progress = timestamp - startTime;
133
+                    var currentPosition = start + ((target - start) * (progress / duration));
134
+                    window.scrollTo(0, currentPosition);
135
+                    if (progress < duration) {
136
+                        requestAnimationFrame(scrollStep);
137
+                    } else {
138
+                        setTimeout(smoothScroll, scrollInterval); // Continues scrolling after a delay
139
+                    }
90 140
                 }
91
-            });
92
-        }, {
93
-            threshold: 0.1
94
-        });
95 141
 
96
-        document.querySelectorAll('.fade-up').forEach(element => {
97
-            observer.observe(element);
142
+                requestAnimationFrame(scrollStep);
143
+            }
144
+        }
145
+    }
146
+
147
+    function playOnly() {
148
+        if (!hasPlayed) {
149
+            playAudio();
150
+            scrollCount++;
151
+            if (scrollCount >= maxScrolls) {
152
+                playAudio();
153
+            } else {
154
+                setTimeout(playOnly, scrollInterval);
155
+            }
156
+        }
157
+    }
158
+
159
+    function handleInteraction() {
160
+        document.body.classList.remove('no-scroll'); // Enable scrolling
161
+        setTimeout(smoothScroll, scrollInterval); // Start smooth scrolling after initial delay
162
+    }
163
+
164
+    // Listen for click or touch event to start auto-scrolling
165
+    window.addEventListener('click', handleInteraction, { once: true });
166
+
167
+     // Intersection Observer for fading in elements
168
+    const observerOptions = {
169
+        root: null,
170
+        rootMargin: '0px',
171
+        threshold: 0.1
172
+    };
173
+
174
+    const observer = new IntersectionObserver((entries, observer) => {
175
+        entries.forEach(entry => {
176
+            if (entry.isIntersecting) {
177
+                entry.target.classList.add('fade-in');
178
+                observer.unobserve(entry.target);
179
+            }
98 180
         });
181
+    }, observerOptions);
182
+
183
+    document.querySelectorAll('.fade-element').forEach(element => {
184
+        observer.observe(element);
99 185
     });
100 186
 });

+ 0
- 119
resources/views/digital-card.blade.php View File

@@ -13,37 +13,6 @@
13 13
         <meta name="csrf-token" content="{{ csrf_token() }}">
14 14
 
15 15
         @vite(['resources/css/app.css','resources/js/app.js'])
16
-        <style>
17
-            html {
18
-                scroll-behavior: smooth;
19
-            }
20
-            body.no-scroll {
21
-                overflow: hidden;
22
-            }
23
-            .fade-element {
24
-                opacity: 0;
25
-                transition: opacity 3s ease-in-out;
26
-            }
27
-            .fade-in {
28
-                opacity: 1;
29
-            }
30
-            .petal-overlay {
31
-                position: fixed; /* Fixes the position to the viewport */
32
-                top: 0;
33
-                left: 0;
34
-                width: 100vw;
35
-                height: 100vh;
36
-                pointer-events: none; /* Allows interactions through the overlay */
37
-                z-index: 9999; /* Ensures it is on top of other elements */
38
-                opacity: 0.3; /* Set the opacity to a lower value */
39
-                display: none; /* Initially hidden */
40
-            }
41
-            .petal-overlay img {
42
-                width: 100%;
43
-                height: 100%;
44
-                object-fit: cover; /* Ensures the image covers the entire container */
45
-            }
46
-        </style>
47 16
     </head>
48 17
     <body class="antialiased font-serif no-scroll">
49 18
         <div role="alert" class="alert alert-info hidden z-40 fixed w-1/2 top-3 right-3">
@@ -55,95 +24,7 @@
55 24
     
56 25
         <audio id="player" loop>
57 26
             <source src="{{ asset('assets/background-musicv2.mp3') }}" type="audio/mp3">
58
-            Your browser does not support the audio element.
59 27
         </audio>
60
-        <script>
61
-            document.addEventListener('click', function () {
62
-                setTimeout(function () {
63
-                    document.getElementById('petalOverlay').style.display = 'block';
64
-                }, 1000); // Delay of 1 second (1000 milliseconds)
65
-            });
66
-        </script>
67
-        <script>
68
-            document.addEventListener('DOMContentLoaded', function() {
69
-                var audioElement = document.getElementById('player');
70
-                var hasPlayed = false; // To ensure audio only plays once upon clicking and scrolling
71
-                var scrollCount = 0;
72
-                var maxScrolls = 6;
73
-                var scrollInterval = 500; // Time in milliseconds between each scroll
74
-                var scrollAmount = window.innerHeight / 6; // Amount to scroll per interval
75
-    
76
-                function playAudio() {
77
-                    if (!hasPlayed) {
78
-                        console.log('play')
79
-                        var playPromise = audioElement.play();
80
-    
81
-                        if (playPromise !== undefined) {
82
-                            playPromise.then(function() {
83
-                                // Automatic playback started!
84
-                                hasPlayed = true; // Prevent further attempts to play
85
-                            }).catch(function(error) {
86
-                                // Automatic playback failed.
87
-                                console.log('Autoplay failed: ' + error);
88
-                            });
89
-                        }
90
-                    }
91
-                }
92
-    
93
-                function smoothScroll() {
94
-                    if (!hasPlayed) {
95
-                        playAudio();
96
-                        scrollCount++;
97
-                        if (scrollCount >= maxScrolls) {
98
-                            playAudio();
99
-                        } else {
100
-                            window.scrollBy(0, scrollAmount); // Smooth scroll a fraction of the window height
101
-                            setTimeout(playOnly, scrollInterval);
102
-                        }
103
-                    }
104
-                }
105
-
106
-                function playOnly() {
107
-                    if (!hasPlayed) {
108
-                        playAudio();
109
-                        scrollCount++;
110
-                        if (scrollCount >= maxScrolls) {
111
-                            playAudio();
112
-                        } else {
113
-                            setTimeout(playOnly, scrollInterval);
114
-                        }
115
-                    }
116
-                }
117
-    
118
-                function handleInteraction() {
119
-                    document.body.classList.remove('no-scroll'); // Enable scrolling
120
-                    setTimeout(smoothScroll, scrollInterval); // Start smooth scrolling after initial delay
121
-                }
122
-    
123
-                // Listen for click or touch event to start auto-scrolling
124
-                window.addEventListener('click', handleInteraction, { once: true });
125
-
126
-                 // Intersection Observer for fading in elements
127
-                const observerOptions = {
128
-                    root: null,
129
-                    rootMargin: '0px',
130
-                    threshold: 0.1
131
-                };
132
-
133
-                const observer = new IntersectionObserver((entries, observer) => {
134
-                    entries.forEach(entry => {
135
-                        if (entry.isIntersecting) {
136
-                            entry.target.classList.add('fade-in');
137
-                            observer.unobserve(entry.target);
138
-                        }
139
-                    });
140
-                }, observerOptions);
141
-
142
-                document.querySelectorAll('.fade-element').forEach(element => {
143
-                    observer.observe(element);
144
-                });
145
-            });
146
-        </script>
147 28
         <div class="parent absolute h-screen w-full">
148 29
             {{-- <audio src="{{asset('assets/paper-ripping.mp3')}}"></audio> --}}
149 30
             @include('components.front-cover')

Loading…
Cancel
Save