Skip to content

Commit 204ce0e

Browse files
committed
update: responsive and scrolling effect
1 parent 874be87 commit 204ce0e

1 file changed

Lines changed: 73 additions & 25 deletions

File tree

app/lecture/src/views/TopScreen.vue

Lines changed: 73 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -23,45 +23,81 @@
2323
})
2424
}
2525
26-
onMounted(() => {
27-
const html_text = "Ri-oneの<span id='target'>新入生歓迎講座</span>へようこそ。"
28-
const conv_text = "Ri-oneの新入生歓迎講座へようこそ。";
29-
const orig_text = "Ri-oneのしんにゅうせいかんげいこうざへようこそ。";
30-
const speed = 130; // Typing speed in milliseconds
31-
var index = 0;
32-
33-
function typeNextCharacter() {
34-
output.value += (orig_text[index]);
35-
index++;
36-
if (index < orig_text.length) {
37-
if (index == 14){
38-
output.value = (conv_text.slice(0, 11));
39-
} else if (index == 18){
40-
output.value = (conv_text.slice(0, 13));
41-
} else if (index == 22){
42-
output.value = (conv_text.slice(0, 15));
43-
}
44-
setTimeout(typeNextCharacter, speed);
45-
} else if (index == orig_text.length) {
46-
output.value = html_text;
26+
const html_text = "Ri-oneの<span id='target'>新入生歓迎講座</span>へようこそ。"
27+
const conv_text = "Ri-oneの新入生歓迎講座へようこそ。";
28+
const orig_text = "Ri-oneのしんにゅうせいかんげいこうざへようこそ。";
29+
const speed = 130; // Typing speed in milliseconds
30+
var index = 0;
31+
32+
function typeNextCharacter() {
33+
output.value += (orig_text[index]);
34+
index++;
35+
if (index < orig_text.length) {
36+
if (index == 14){
37+
output.value = (conv_text.slice(0, 11));
38+
} else if (index == 18){
39+
output.value = (conv_text.slice(0, 13));
40+
} else if (index == 22){
41+
output.value = (conv_text.slice(0, 15));
42+
}
43+
setTimeout(typeNextCharacter, speed);
44+
} else if (index == orig_text.length) {
45+
output.value = html_text;
46+
}
47+
};
48+
49+
let isScrolling = false;
50+
51+
function startScrolling() {
52+
isScrolling = true;
53+
var scrollText = document.getElementById('scroll-text');
54+
var scrollContainer = document.getElementById('scroll-container');
55+
var containerWidth = scrollContainer.offsetWidth;
56+
var textWidth = scrollText.offsetWidth;
57+
58+
// Reset position
59+
scrollText.style.left = containerWidth + 'px';
60+
61+
function animate() {
62+
if (!isScrolling) return;
63+
var currentLeft = parseFloat(scrollText.style.left);
64+
scrollText.style.left = (currentLeft - 2) + 'px'; // Adjust speed by changing 2
65+
if (currentLeft + textWidth > 0) {
66+
requestAnimationFrame(animate);
67+
} else {
68+
startScrolling(); // Repeat animation
4769
}
48-
};
70+
}
71+
requestAnimationFrame(animate);
72+
}
73+
74+
function stopScrolling() {
75+
isScrolling = false;
76+
}
4977
50-
typeNextCharacter();
78+
onMounted(() => {
79+
typeNextCharacter();
80+
startScrolling();
5181
});
5282
5383
onUnmounted(() => {
84+
stopScrolling()
5485
output.value = "";
5586
});
5687
</script>
5788

5889
<template>
5990
<div class="container mx-auto my-16">
6091
<h1 v-html="output" id="output" class="text-5xl"></h1><span class="typing-cursor"></span>
61-
<div class="mt-2">※レスポンシブ非対応なのは内緒です。だって面倒くさ(ry</div>
92+
<!-- <div class="mt-2">※レスポンシブ非対応なのは内緒です。だって面倒くさ(ry</div> -->
93+
<div id="scroll-container" class="mx-auto w-4/6 mt-2">
94+
<div id="scroll-text" class="text-md">ついにレスポンシブ対応しました! ところで、誰がこのページをスマホで開くのでしょうか...</div>
95+
</div>
6296
</div>
6397

64-
<table class="mx-auto mt-20 sm:w-5/6 md:w-3/6 bg-neutral-900 rounded-lg border-2 border-solid border-green-700">
98+
99+
100+
<table class="mx-auto mt-20 w-full sm:w-5/6 md:w-4/6 bg-neutral-900 rounded-lg border-2 border-solid border-green-700">
65101
<div class="flex-col space-y-0 space-x-0 text-start divide-y divide-green-600">
66102
<div v-for="(lecture, index) in lectures" class="w-full py-5 pl-5 hover:bg-green-600 hover:scale-105" @click="navigate(index)">
67103
第{{ oneOriented(index) }}講 {{ lecture.title }}
@@ -80,6 +116,18 @@
80116
display: inline-block;
81117
}
82118
119+
#scroll-container {
120+
overflow: hidden;
121+
white-space: nowrap;
122+
box-sizing: border-box;
123+
}
124+
125+
#scroll-text {
126+
display: inline-block;
127+
padding-right: 10%; /* Ensures the text starts off-screen */
128+
position: relative;
129+
}
130+
83131
.typing-cursor {
84132
display: inline-block;
85133
width: 15px;

0 commit comments

Comments
 (0)