Browse Source

test inteception left and right

master
farhan 5 months ago
parent
commit
4823a9f320
1 changed files with 22 additions and 12 deletions
  1. 22
    12
      resources/js/app.js

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

@@ -55,12 +55,12 @@ const countdownTimer = setInterval(() => {
55 55
 $(function() {
56 56
     var partLeftPos = 0;
57 57
     var partRightPos = 0;
58
-    
59
-    $(window).scroll(function(event) {
60
-        var distance = $(this).scrollTop() * 2;
58
+
59
+    function updatePositions() {
60
+        var distance = $(window).scrollTop() * 2;
61 61
         var left = partLeftPos - distance;
62 62
         var right = partRightPos - distance;
63
-        
63
+
64 64
         $('.left').css('left', left + "px");
65 65
         $('.right').css('right', right + "px");
66 66
 
@@ -72,19 +72,29 @@ $(function() {
72 72
 
73 73
         // Toggle visibility and z-index
74 74
         if (isLeftOffScreen && left < 0) {
75
-            $('.left').css('left', 0 + "px");
76
-            $('.right').css('right', 0 + "px");
77
-            $('.parent').removeClass(['z-30']);
75
+            $('.parent').removeClass('z-30');
78 76
         } else {
79
-            
80
-            $('.parent').addClass(['z-30']);
77
+            $('.parent').addClass('z-30');
78
+        }
79
+    }
80
+
81
+    // Initial positions update
82
+    updatePositions();
83
+
84
+    // Listen to scroll events using requestAnimationFrame for smooth animation
85
+    var ticking = false;
86
+    $(window).scroll(function() {
87
+        if (!ticking) {
88
+            window.requestAnimationFrame(function() {
89
+                updatePositions();
90
+                ticking = false;
91
+            });
81 92
         }
93
+        ticking = true;
82 94
     });
83
-    
84
-    // Initially check visibility on page load
85
-    $(window).trigger('scroll');
86 95
 });
87 96
 
97
+
88 98
 document.addEventListener('click', function () {
89 99
     setTimeout(function () {
90 100
         document.getElementById('petalOverlay').style.display = 'block';

Loading…
Cancel
Save