Skip to content

Commit f236497

Browse files
committed
chore: enhance Advanced Parallax Container with new features and performance improvements
- Updated the parallax block to version 1.0.8, introducing new attributes for visibility trigger, detection boundary, and mouse interaction settings. - Added support for advanced effects configuration, allowing users to customize depth levels, z-index, and mouse sensitivity. - Implemented utility functions for parallax calculations and improved rendering logic for better performance and user experience. - Introduced a debug panel and overlays for enhanced visibility and interaction tracking during development.
1 parent 40896b1 commit f236497

27 files changed

+4143
-798
lines changed

src/blocks-interactivity/parallax/attributes.ts

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,24 @@ addFilter(
7272
attributes.aggressiveApparelParallax.delay.toString() + 'ms',
7373
'--parallax-easing': attributes.aggressiveApparelParallax.easing,
7474
};
75+
76+
// Save effects data for all blocks inside parallax containers
77+
// Apply effects to any element that has parallax effects configured
78+
if (attributes.aggressiveApparelParallax?.effects) {
79+
const effects = attributes.aggressiveApparelParallax.effects;
80+
81+
// Check if any effects are configured (including default values for layering control)
82+
const hasAnyEffects =
83+
effects.zoom ||
84+
effects.depthLevel ||
85+
effects.zIndex ||
86+
effects.opacity ||
87+
effects.rotation;
88+
89+
if (hasAnyEffects) {
90+
extraProps['data-parallax-effects'] = JSON.stringify(effects);
91+
}
92+
}
7593
}
7694

7795
return extraProps;

src/blocks-interactivity/parallax/block.json

Lines changed: 47 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
"$schema": "https://schemas.wp.org/trunk/block.json",
33
"apiVersion": 3,
44
"name": "aggressive-apparel/parallax",
5-
"version": "1.0.5",
5+
"version": "1.0.8",
66
"title": "Advanced Parallax Container",
77
"category": "widgets",
88
"icon": "cover-image",
@@ -21,26 +21,62 @@
2121
"type": "number",
2222
"default": 50
2323
},
24-
"enableIntersectionObserver": {
25-
"type": "boolean",
26-
"default": true
27-
},
28-
"intersectionThreshold": {
24+
"visibilityTrigger": {
2925
"type": "number",
30-
"default": 0.1
26+
"default": 0.3
27+
},
28+
"detectionBoundary": {
29+
"type": "object",
30+
"default": {
31+
"top": "0%",
32+
"right": "0%",
33+
"bottom": "0%",
34+
"left": "0%"
35+
}
3136
},
3237
"enableMouseInteraction": {
3338
"type": "boolean",
3439
"default": false
3540
},
41+
"debugMode": {
42+
"type": "boolean",
43+
"default": false
44+
},
3645
"parallaxDirection": {
3746
"type": "string",
38-
"enum": ["up", "down", "both"],
3947
"default": "down"
4048
},
41-
"debugMode": {
42-
"type": "boolean",
43-
"default": false
49+
"mouseInfluenceMultiplier": {
50+
"type": "number",
51+
"default": 0.5
52+
},
53+
"maxMouseTranslation": {
54+
"type": "number",
55+
"default": 20
56+
},
57+
"mouseSensitivityThreshold": {
58+
"type": "number",
59+
"default": 0.001
60+
},
61+
"depthIntensityMultiplier": {
62+
"type": "number",
63+
"default": 50
64+
},
65+
"transitionDuration": {
66+
"type": "number",
67+
"default": 0.1
68+
},
69+
"perspectiveDistance": {
70+
"type": "number",
71+
"default": 1000
72+
},
73+
"maxMouseRotation": {
74+
"type": "number",
75+
"default": 5
76+
},
77+
"parallaxDepth": {
78+
"type": "number",
79+
"default": 1.0
4480
}
4581
},
4682
"providesContext": {

src/blocks-interactivity/parallax/utils.ts renamed to src/blocks-interactivity/parallax/calculations.ts

Lines changed: 52 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -34,67 +34,66 @@ export function calculateParallaxMovement(
3434
scrollProgress: number,
3535
intensity: number,
3636
speed: number,
37-
direction: 'up' | 'down' | 'both' | 'none',
38-
mouseX?: number,
39-
mouseY?: number,
40-
enableMouseInteraction?: boolean
37+
direction: string,
38+
mouseX: number,
39+
mouseY: number,
40+
enableMouseInteraction: boolean,
41+
options: {
42+
mouseInfluenceMultiplier: number;
43+
maxMouseTranslation: number;
44+
depthFactor: number;
45+
}
4146
): { x: number; y: number } {
42-
const adjustedIntensity = intensity / 100;
43-
44-
// Initialize movement values
45-
let scrollMovementY = 0;
46-
let mouseMovementY = 0;
47-
let mouseMovementX = 0;
47+
// Scroll movement
48+
let scrollX = 0;
49+
let scrollY = 0;
50+
const movement = scrollProgress * intensity * speed;
4851

49-
// Calculate scroll-based movement (primarily affects Y axis)
5052
switch (direction) {
5153
case 'up':
52-
scrollMovementY = -scrollProgress * 100 * adjustedIntensity * speed;
54+
scrollY = -movement;
5355
break;
5456
case 'down':
55-
scrollMovementY = scrollProgress * 100 * adjustedIntensity * speed;
57+
scrollY = movement;
5658
break;
57-
case 'both': {
58-
const centeredProgress = (scrollProgress - 0.5) * 2;
59-
scrollMovementY = centeredProgress * 100 * adjustedIntensity * speed;
59+
case 'left':
60+
scrollX = -movement;
61+
break;
62+
case 'right':
63+
scrollX = movement;
64+
break;
65+
case 'both':
66+
scrollX = movement * 0.5;
67+
scrollY = movement * 0.5;
6068
break;
61-
}
62-
case 'none':
63-
default:
64-
scrollMovementY = 0;
6569
}
6670

67-
// Add mouse interaction if enabled (affects both X and Y axes for 3D effect)
68-
if (enableMouseInteraction && mouseX !== undefined && mouseY !== undefined) {
69-
// Mouse influence: convert mouse position to movement offset
70-
// mouseX and mouseY are normalized 0-1, convert to -1 to 1 range
71-
const mouseOffsetX = (mouseX - 0.5) * 2; // -1 to 1
72-
const mouseOffsetY = (mouseY - 0.5) * 2; // -1 to 1
73-
74-
// Apply mouse influence based on direction
75-
switch (direction) {
76-
case 'up':
77-
case 'down':
78-
// Mouse creates subtle 3D movement: horizontal mouse affects horizontal parallax
79-
mouseMovementX = mouseOffsetX * 30 * adjustedIntensity * speed;
80-
mouseMovementY = mouseOffsetY * 50 * adjustedIntensity * speed;
81-
break;
82-
case 'both':
83-
// Full 3D mouse parallax effect
84-
mouseMovementX = mouseOffsetX * 40 * adjustedIntensity * speed;
85-
mouseMovementY = mouseOffsetY * 40 * adjustedIntensity * speed;
86-
break;
87-
case 'none':
88-
default:
89-
mouseMovementX = 0;
90-
mouseMovementY = 0;
91-
}
71+
// Mouse movement
72+
let mouseXTrans = 0;
73+
let mouseYTrans = 0;
74+
75+
if (enableMouseInteraction) {
76+
const { mouseInfluenceMultiplier, maxMouseTranslation, depthFactor } =
77+
options;
78+
const mouseInfluence = mouseInfluenceMultiplier * intensity * depthFactor;
79+
80+
mouseXTrans = (mouseX - 0.5) * mouseInfluence * speed;
81+
mouseYTrans = (mouseY - 0.5) * mouseInfluence * speed;
82+
83+
// Clamp
84+
mouseXTrans = Math.max(
85+
-maxMouseTranslation,
86+
Math.min(maxMouseTranslation, mouseXTrans)
87+
);
88+
mouseYTrans = Math.max(
89+
-maxMouseTranslation,
90+
Math.min(maxMouseTranslation, mouseYTrans)
91+
);
9292
}
9393

94-
// Combine scroll and mouse movement (mouse has less influence)
9594
return {
96-
x: mouseMovementX * 0.3, // Mouse X influence
97-
y: scrollMovementY + mouseMovementY * 0.3, // Scroll Y + Mouse Y influence
95+
x: scrollX + mouseXTrans,
96+
y: scrollY + mouseYTrans,
9897
};
9998
}
10099

@@ -136,14 +135,17 @@ export function getElementStableId(
136135
return `${blockType}-${index}`;
137136
}
138137

138+
/**
139+
* Debounces a function call.
140+
*/
139141
/**
140142
* Debounces a function call.
141143
*/
142144
export function debounce<T extends Function>(func: T, wait: number): Function {
143145
let timeout: number;
144146
return (...args: any[]) => {
145147
clearTimeout(timeout);
146-
timeout = setTimeout(() => func(...args), wait);
148+
timeout = window.setTimeout(() => func(...args), wait);
147149
};
148150
}
149151

@@ -156,7 +158,7 @@ export function throttle<T extends Function>(func: T, limit: number): Function {
156158
if (!inThrottle) {
157159
func(...args);
158160
inThrottle = true;
159-
setTimeout(() => (inThrottle = false), limit);
161+
window.setTimeout(() => (inThrottle = false), limit);
160162
}
161163
};
162164
}

0 commit comments

Comments
 (0)