mirror of
https://github.com/LJ5O/website.git
synced 2026-08-11 22:54:46 +02:00
Dynamic text component
This commit is contained in:
57
src/components/home/dynamicOccupation.vue
Normal file
57
src/components/home/dynamicOccupation.vue
Normal file
@@ -0,0 +1,57 @@
|
|||||||
|
<template>
|
||||||
|
<h2>{{ displayedWorld }}</h2>
|
||||||
|
</template>
|
||||||
|
|
||||||
|
<script setup>
|
||||||
|
import { ref, onMounted, onUnmounted } from 'vue';
|
||||||
|
|
||||||
|
const props = defineProps({
|
||||||
|
sentences:{
|
||||||
|
type:Array,
|
||||||
|
required:true
|
||||||
|
},
|
||||||
|
speed:{
|
||||||
|
type:Number,
|
||||||
|
required:false,
|
||||||
|
default: 250
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
let active = ref(true);
|
||||||
|
let chosenWord = ref(0);
|
||||||
|
let currentLetter = ref(0);
|
||||||
|
let displayedWorld = ref("");
|
||||||
|
|
||||||
|
const tick = ()=>{
|
||||||
|
const word = props.sentences[chosenWord.value];
|
||||||
|
if(currentLetter.value < word.length){
|
||||||
|
//We still have letters to display
|
||||||
|
displayedWorld.value = displayedWorld.value + word.at(currentLetter.value);
|
||||||
|
currentLetter.value++;
|
||||||
|
}else{
|
||||||
|
//Next word, reset
|
||||||
|
displayedWorld.value = "";
|
||||||
|
currentLetter.value = 0;
|
||||||
|
chosenWord.value = (chosenWord.value+1) % props.sentences.length;
|
||||||
|
}
|
||||||
|
|
||||||
|
if(active.value) setTimeout(tick, props.speed);
|
||||||
|
}
|
||||||
|
|
||||||
|
onMounted(tick);
|
||||||
|
|
||||||
|
onUnmounted(()=>{active.value=false;})
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<style scoped>
|
||||||
|
|
||||||
|
h2{
|
||||||
|
height: 1.5em;
|
||||||
|
font-size: 1.5em;
|
||||||
|
margin-top: 10px;
|
||||||
|
margin-bottom: 5px;
|
||||||
|
width: fit-content;
|
||||||
|
border-right: 2px solid #EAEAEA;
|
||||||
|
}
|
||||||
|
|
||||||
|
</style>
|
||||||
@@ -8,7 +8,7 @@
|
|||||||
<div id="name_div_right_container">
|
<div id="name_div_right_container">
|
||||||
<div class="test" id="welcome_text_div">
|
<div class="test" id="welcome_text_div">
|
||||||
<h1>Hello ! I'm {{ $t('message.hello') }} </h1>
|
<h1>Hello ! I'm {{ $t('message.hello') }} </h1>
|
||||||
<h2>AI enthousiast</h2>
|
<dynamicOccupation id="dynamic_occupation" :sentences="occupations" />
|
||||||
</div>
|
</div>
|
||||||
<div id="social_networks" class="test">
|
<div id="social_networks" class="test">
|
||||||
<div class="network">
|
<div class="network">
|
||||||
@@ -27,10 +27,10 @@
|
|||||||
</div> <!-- Welcome Div -->
|
</div> <!-- Welcome Div -->
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
<script>
|
<script setup>
|
||||||
export default {
|
import dynamicOccupation from './dynamicOccupation.vue';
|
||||||
|
|
||||||
}
|
const occupations = ["AI enthousiast", "I don't know", "Test Hello World"]
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<style scoped>
|
<style scoped>
|
||||||
@@ -80,6 +80,8 @@ export default {
|
|||||||
}
|
}
|
||||||
#welcome_text_div h1{
|
#welcome_text_div h1{
|
||||||
margin-top: 100px;
|
margin-top: 100px;
|
||||||
|
margin-bottom: 10px;
|
||||||
|
font-size: 2em;
|
||||||
}
|
}
|
||||||
|
|
||||||
#social_networks{
|
#social_networks{
|
||||||
|
|||||||
Reference in New Issue
Block a user