Browse Source

fix scroll front cover

master
farhan 5 months ago
parent
commit
427d5cbf82
1 changed files with 20 additions and 7 deletions
  1. 20
    7
      resources/views/digital-card.blade.php

+ 20
- 7
resources/views/digital-card.blade.php View File

91
                 }
91
                 }
92
     
92
     
93
                 function smoothScroll() {
93
                 function smoothScroll() {
94
-                    if (!hasPlayed) {
94
+                if (!hasPlayed) {
95
+                    playAudio();
96
+                    scrollCount++;
97
+                    if (scrollCount >= maxScrolls) {
95
                         playAudio();
98
                         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);
99
+                    } else {
100
+                        // Calculate scroll position
101
+                        var currentScroll = window.pageYOffset || document.documentElement.scrollTop;
102
+                        var targetScroll = currentScroll + scrollAmount;
103
+
104
+                        // Smooth scroll using requestAnimationFrame
105
+                        function scrollStep() {
106
+                            if (currentScroll < targetScroll) {
107
+                                window.scrollTo(0, currentScroll += 5); // Adjust speed here (e.g., +=5)
108
+                                requestAnimationFrame(scrollStep);
109
+                            }
102
                         }
110
                         }
111
+
112
+                        scrollStep(); // Initiates the smooth scrolling process
113
+                        setTimeout(smoothScroll, scrollInterval); // Continues scrolling after a delay
103
                     }
114
                     }
104
                 }
115
                 }
116
+}
117
+
105
 
118
 
106
                 function playOnly() {
119
                 function playOnly() {
107
                     if (!hasPlayed) {
120
                     if (!hasPlayed) {

Loading…
Cancel
Save