Issue resolved

Signed-off-by: zubairrafi <walleeva2018@gmail.com>
This commit is contained in:
zubairrafi
2025-07-12 11:26:58 +06:00
parent ea8a04eb3b
commit 936bca258a
3 changed files with 118 additions and 138 deletions

View File

@@ -2,7 +2,7 @@ import code from '@content/TextAnimations/ScrollFloat/ScrollFloat.vue?raw'
import type { CodeObject } from '../../../types/code' import type { CodeObject } from '../../../types/code'
export const scrollFloatCode: CodeObject = { export const scrollFloatCode: CodeObject = {
cli: `npx jsrepo add https://vue-bits.dev/ui/Components/ProfileCard`, cli: `npx jsrepo add https://vue-bits.dev/ui/TextAnimations/ScrollFloat`,
usage: `<template> usage: `<template>
<ScrollFloat <ScrollFloat
:children="scrollText" :children="scrollText"

View File

@@ -1,25 +1,25 @@
<template> <template>
<h2 ref="containerRef" :class="`scroll-float ${containerClassName}`"> <h2 ref="containerRef" :class="`overflow-hidden ${containerClassName}`">
<span :class="`scroll-float-text ${textClassName}`"> <span :class="`inline-block text-center leading-relaxed font-black ${textClassName}`" style="font-size: clamp(1.6rem, 8vw, 10rem);">
<span <span
v-for="(char, index) in splitText" v-for="(char, index) in splitText"
:key="index" :key="index"
class="char" class="inline-block char"
> >
{{ char === " " ? "\u00A0" : char }} {{ char === " " ? "\u00A0" : char }}
</span> </span>
</span> </span>
</h2> </h2>
</template> </template>
<script setup lang="ts"> <script setup lang="ts">
import { ref, computed, onMounted, onUnmounted, watch } from 'vue'; import { ref, computed, onMounted, onUnmounted, watch } from 'vue';
import { gsap } from 'gsap'; import { gsap } from 'gsap';
import { ScrollTrigger } from 'gsap/ScrollTrigger'; import { ScrollTrigger } from 'gsap/ScrollTrigger';
gsap.registerPlugin(ScrollTrigger); gsap.registerPlugin(ScrollTrigger);
interface Props { interface Props {
children: string; children: string;
scrollContainerRef?: { current: HTMLElement | null }; scrollContainerRef?: { current: HTMLElement | null };
containerClassName?: string; containerClassName?: string;
@@ -29,9 +29,9 @@
scrollStart?: string; scrollStart?: string;
scrollEnd?: string; scrollEnd?: string;
stagger?: number; stagger?: number;
} }
const props = withDefaults(defineProps<Props>(), { const props = withDefaults(defineProps<Props>(), {
containerClassName: '', containerClassName: '',
textClassName: '', textClassName: '',
animationDuration: 1, animationDuration: 1,
@@ -39,17 +39,17 @@
scrollStart: 'center bottom+=50%', scrollStart: 'center bottom+=50%',
scrollEnd: 'bottom bottom-=40%', scrollEnd: 'bottom bottom-=40%',
stagger: 0.03 stagger: 0.03
}); });
const containerRef = ref<HTMLElement | null>(null); const containerRef = ref<HTMLElement | null>(null);
let scrollTriggerInstance: ScrollTrigger | null = null; let scrollTriggerInstance: ScrollTrigger | null = null;
const splitText = computed(() => { const splitText = computed(() => {
const text = typeof props.children === 'string' ? props.children : ''; const text = typeof props.children === 'string' ? props.children : '';
return text.split(""); return text.split("");
}); });
const initializeAnimation = () => { const initializeAnimation = () => {
const el = containerRef.value; const el = containerRef.value;
if (!el) return; if (!el) return;
@@ -93,19 +93,19 @@
); );
scrollTriggerInstance = tl.scrollTrigger || null; scrollTriggerInstance = tl.scrollTrigger || null;
}; };
onMounted(() => { onMounted(() => {
initializeAnimation(); initializeAnimation();
}); });
onUnmounted(() => { onUnmounted(() => {
if (scrollTriggerInstance) { if (scrollTriggerInstance) {
scrollTriggerInstance.kill(); scrollTriggerInstance.kill();
} }
}); });
watch( watch(
[ [
() => props.children, () => props.children,
() => props.scrollContainerRef, () => props.scrollContainerRef,
@@ -119,23 +119,5 @@
initializeAnimation(); initializeAnimation();
}, },
{ deep: true } { deep: true }
); );
</script> </script>
<style scoped>
.scroll-float {
overflow: hidden;
}
.scroll-float-text {
display: inline-block;
font-size: clamp(1.6rem, 8vw, 10rem);
font-weight: 900;
text-align: center;
line-height: 1.5;
}
.char {
display: inline-block;
}
</style>

View File

@@ -1,5 +1,4 @@
<template> <template>
<div class="profile-card-demo">
<TabbedLayout> <TabbedLayout>
<template #preview> <template #preview>
<div <div
@@ -47,7 +46,6 @@
<CliInstallation :command="scrollFloatCode.cli" /> <CliInstallation :command="scrollFloatCode.cli" />
</template> </template>
</TabbedLayout> </TabbedLayout>
</div>
</template> </template>
<script setup lang="ts"> <script setup lang="ts">