srcdev-nuxt-components 2.1.20 → 2.1.22
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.
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
<template>
|
|
2
|
+
<div class="clip-element-wrapper" ref="container" :class="elementClasses">
|
|
3
|
+
<div class="clipped-element" :style="`--_clip-path: inset(${clipOffset}px 0 0 0)`" ref="clipElement">
|
|
4
|
+
<slot name="default"></slot>
|
|
5
|
+
</div>
|
|
6
|
+
</div>
|
|
7
|
+
</template>
|
|
8
|
+
|
|
9
|
+
<script lang="ts" setup>
|
|
10
|
+
|
|
11
|
+
const props = defineProps({
|
|
12
|
+
maxClip: {
|
|
13
|
+
type: Number,
|
|
14
|
+
default: 100,
|
|
15
|
+
},
|
|
16
|
+
styleClassPassthrough: {
|
|
17
|
+
type: Array as PropType<string[]>,
|
|
18
|
+
default: () => [],
|
|
19
|
+
},
|
|
20
|
+
});
|
|
21
|
+
|
|
22
|
+
const { elementClasses } = useStyleClassPassthrough(props.styleClassPassthrough);
|
|
23
|
+
|
|
24
|
+
|
|
25
|
+
const container = ref(null);
|
|
26
|
+
const clipElement = ref<HTMLDivElement | null>(null);
|
|
27
|
+
const clipOffset = ref(0);
|
|
28
|
+
|
|
29
|
+
const updateClip = () => {
|
|
30
|
+
|
|
31
|
+
if (clipElement.value) {
|
|
32
|
+
|
|
33
|
+
const topPosition = Math.floor(clipElement.value.getBoundingClientRect().top);
|
|
34
|
+
|
|
35
|
+
if (topPosition < props.maxClip && topPosition > 0) {
|
|
36
|
+
clipOffset.value = props.maxClip - topPosition;
|
|
37
|
+
}
|
|
38
|
+
else if (topPosition < 0) {
|
|
39
|
+
clipOffset.value = props.maxClip + Math.abs(topPosition);
|
|
40
|
+
}
|
|
41
|
+
else if (topPosition > props.maxClip) {
|
|
42
|
+
clipOffset.value = 0;
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
};
|
|
46
|
+
|
|
47
|
+
onMounted(() => {
|
|
48
|
+
|
|
49
|
+
if (import.meta.client) {
|
|
50
|
+
updateClip(); // Initial check
|
|
51
|
+
window.addEventListener('scroll', updateClip, { passive: true });
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
});
|
|
55
|
+
|
|
56
|
+
onBeforeUnmount(() => {
|
|
57
|
+
window.removeEventListener('scroll', updateClip);
|
|
58
|
+
});
|
|
59
|
+
|
|
60
|
+
|
|
61
|
+
</script>
|
|
62
|
+
|
|
63
|
+
<style lang="css">
|
|
64
|
+
.clip-element-wrapper {
|
|
65
|
+
position: relative;
|
|
66
|
+
overflow: hidden;
|
|
67
|
+
}
|
|
68
|
+
.clipped-element {
|
|
69
|
+
width: 100%;
|
|
70
|
+
clip-path: var(--_clip-path);
|
|
71
|
+
display: block;
|
|
72
|
+
}
|
|
73
|
+
</style>
|
package/package.json
CHANGED