@madj2k/fe-frontend-kit 2.0.33 → 2.0.35
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json
CHANGED
|
@@ -8,10 +8,11 @@
|
|
|
8
8
|
* - Reusable for any type of element (quotes, sections, etc.)
|
|
9
9
|
* - Fully configurable: class name, threshold, delay
|
|
10
10
|
* - Designed for CMS contexts with dynamically loaded content
|
|
11
|
+
* - Triggers an event that can be used for custom animations
|
|
11
12
|
*
|
|
12
13
|
* @author Steffen Kroggel <developer@steffenkroggel.de>
|
|
13
14
|
* @copyright 2025 Steffen Kroggel
|
|
14
|
-
* @version 1.0.
|
|
15
|
+
* @version 1.0.2
|
|
15
16
|
* @license GNU General Public License v3.0
|
|
16
17
|
* @see https://www.gnu.org/licenses/gpl-3.0.en.html
|
|
17
18
|
*
|
|
@@ -34,11 +35,17 @@
|
|
|
34
35
|
* document.querySelectorAll('.js-element-in-viewport').forEach((el) => {
|
|
35
36
|
* new Madj2kElementInViewport(el, {
|
|
36
37
|
* visibleClass: 'is-in-viewport',
|
|
37
|
-
* threshold:
|
|
38
|
+
* threshold: 0.5
|
|
38
39
|
* });
|
|
39
40
|
* });
|
|
40
|
-
|
|
41
|
-
|
|
41
|
+
*
|
|
42
|
+
* @example
|
|
43
|
+
* // Event listener
|
|
44
|
+
* document.addEventListener('madj2k-element-in-viewport-active', () => {
|
|
45
|
+
* // do something
|
|
46
|
+
* });
|
|
47
|
+
*
|
|
48
|
+
* */
|
|
42
49
|
class Madj2kElementInViewport {
|
|
43
50
|
config = {
|
|
44
51
|
visibleClass: 'is-in-viewport',
|
|
@@ -64,6 +71,17 @@ class Madj2kElementInViewport {
|
|
|
64
71
|
this.element = element;
|
|
65
72
|
this.config = { ...this.config, ...config };
|
|
66
73
|
|
|
74
|
+
const viewportHeight = window.innerHeight;
|
|
75
|
+
const elementHeight = element.offsetHeight;
|
|
76
|
+
|
|
77
|
+
if (elementHeight > viewportHeight) {
|
|
78
|
+
const adjustedThreshold = (viewportHeight * this.config.threshold) / elementHeight;
|
|
79
|
+
this._log(
|
|
80
|
+
`Element taller than viewport. Original threshold ${this.config.threshold} adjusted to ${adjustedThreshold.toFixed(3)}`
|
|
81
|
+
);
|
|
82
|
+
this.config.threshold = Math.min(adjustedThreshold, 1);
|
|
83
|
+
}
|
|
84
|
+
|
|
67
85
|
this._log('Initialized with config:', this.config);
|
|
68
86
|
this._observe();
|
|
69
87
|
}
|
|
@@ -102,6 +120,13 @@ class Madj2kElementInViewport {
|
|
|
102
120
|
this.element.classList.add(this.config.visibleClass);
|
|
103
121
|
observer.unobserve(this.element);
|
|
104
122
|
this._log(`Class "${this.config.visibleClass}" added.`);
|
|
123
|
+
|
|
124
|
+
// Custom event dispatch
|
|
125
|
+
const event = new CustomEvent('madj2k-element-in-viewport-active');
|
|
126
|
+
this.element.dispatchEvent(event);
|
|
127
|
+
|
|
128
|
+
this._log(`Event fired.`);
|
|
129
|
+
|
|
105
130
|
}
|
|
106
131
|
|
|
107
132
|
/**
|