英文:
How to make typing animation with Tailwind? | next13.4 & tailwind
问题
我遇到了一点文字输入动画的问题。我想要对这一行中的最后一个单词进行动画处理。我已经在tailwind.config.js中添加了一些改进,但是闪烁动画可以工作,但打字动画不能。
<h1 className='head_text text-center'>
Discover & Share
<br className='max-md:hidden' />
<span className='green_gradient text-center'>
AI-Powered <span className='overflow-hidden whitespace-nowrap font-mono animate-typing border-r-4'>Ideas</span>
</span>
</h1>
tailwind.config.js
/** @type {import('tailwindcss').Config} */
module.exports = {
content: [
'./pages/**/*.{js,ts,jsx,tsx,mdx}',
'./components/**/*.{js,ts,jsx,tsx,mdx}',
'./app/**/*.{js,ts,jsx,tsx,mdx}',
],
darkMode: 'class',
theme: {
extend: {
animation: {
typing: 'typing 2s steps(6), blink 1s infinite',
},
keyframes: {
typing: {
from: { width: '0' },
to: { width: '6ch' },
},
blink: {
from: { 'border-right-color': 'transparent' },
to: { 'border-right-color': 'black' },
},
},
fontFamily: {
satoshi: ['Satoshi', 'sans-serif'],
inter: ['Inter', 'sans-serif'],
},
colors: {
'primary-orange': '#FF5722',
},
},
},
plugins: [],
};
希望这能帮助你解决问题。
英文:
I'm stuck a little bit with text typing animation. I want to animate the last word in this line. I've already added some improvements to tailwind.config.js, but the blinking animation is working, and the typing animation isn't.
<h1 className='head_text text-center'>
Discover & Share
<br className='max-md:hidden' />
<span className='green_gradient text-center'>
AI-Powered <span className='overflow-hidden whitespace-nowrap font-mono animate-typing border-r-4'>Ideas</span>
</span>
</h1>
tailwind.config.js
/** @type {import('tailwindcss').Config} */
module.exports = {
content: [
'./pages/**/*.{js,ts,jsx,tsx,mdx}',
'./components/**/*.{js,ts,jsx,tsx,mdx}',
'./app/**/*.{js,ts,jsx,tsx,mdx}',
],
darkMode: 'class',
theme: {
extend: {
animation: {
typing: 'typing 2s steps(6), blink 1s infinite',
},
keyframes: {
typing: {
from: { width: '0' },
to: { width: '6ch' },
},
blink: {
from: { 'border-right-color': 'transparent' },
to: { 'border-right-color': 'black' },
},
},
fontFamily: {
satoshi: ['Satoshi', 'sans-serif'],
inter: ['Inter', 'sans-serif'],
},
colors: {
'primary-orange': '#FF5722',
},
},
},
plugins: [],
};
答案1
得分: 1
<span>
元素默认具有 display: inline
,并且 width
对内联元素没有影响。您可以考虑在 <span>
上应用 display: inline-block
类型的实用程序类,以使 width
生效:
<!-- begin snippet: js hide: false console: false babel: false -->
<!-- language: lang-js -->
tailwind.config = {
theme: {
extend: {
animation: {
typing: 'typing 2s steps(6), blink 1s infinite',
},
keyframes: {
typing: {
from: {
width: '0'
},
to: {
width: '6ch'
},
},
blink: {
from: {
'border-right-color': 'transparent'
},
to: {
'border-right-color': 'black'
},
},
},
fontFamily: {
satoshi: ['Satoshi', 'sans-serif'],
inter: ['Inter', 'sans-serif'],
},
colors: {
'primary-orange': '#FF5722',
},
},
},
}
<!-- language: lang-html -->
<script src="https://cdn.tailwindcss.com/3.3.3"></script>
<h1 class='head_text text-center'>
Discover & Share
<br class='max-md:hidden' />
<span class='green_gradient text-center'>
AI-Powered <span class='inline-block overflow-hidden whitespace-nowrap font-mono animate-typing border-r-4'>Ideas</span>
</span>
</h1>
<!-- end snippet -->
英文:
<span>
elements have display: inline
by default and width
has no effect on inline elements. You could consider applying display: inline-block
on the <span>
via the inline-block
utility class so that width
takes effect:
<!-- begin snippet: js hide: false console: false babel: false -->
<!-- language: lang-js -->
tailwind.config = {
theme: {
extend: {
animation: {
typing: 'typing 2s steps(6), blink 1s infinite',
},
keyframes: {
typing: {
from: {
width: '0'
},
to: {
width: '6ch'
},
},
blink: {
from: {
'border-right-color': 'transparent'
},
to: {
'border-right-color': 'black'
},
},
},
fontFamily: {
satoshi: ['Satoshi', 'sans-serif'],
inter: ['Inter', 'sans-serif'],
},
colors: {
'primary-orange': '#FF5722',
},
},
},
}
<!-- language: lang-html -->
<script src="https://cdn.tailwindcss.com/3.3.3"></script>
<h1 class='head_text text-center'>
Discover & Share
<br class='max-md:hidden' />
<span class='green_gradient text-center'>
AI-Powered <span class='inline-block overflow-hidden whitespace-nowrap font-mono animate-typing border-r-4'>Ideas</span>
</span>
</h1>
<!-- end snippet -->
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论