【发布时间】:2021-05-27 00:48:22
【问题描述】:
我想在网站的主页上显示单词“Hello”。我使用 CSS 在页面开始加载时进行“Hello”过渡。我想实现一个随机播放的动画,在不同语言的单词 Hello 之间随机播放。我想用一个动画来做到这一点,当“你好”在开始时向上滑动时,“你好”向上滑动更多,淡出并消失。当这种情况发生时,例如“Bonjour”从下方滑出并发生。我想象这会永远重复。
有没有办法使用 CSS、JavaScript、Jquery 或任何其他网络工具来实现此类动画?下面是我的 HTML、CSS 和 JS 结构,它只在页面加载时实现初始转换:
<body>
<section>
<h1 id="switch">Hello</h1>
</section>
</body>
section {
text-align: left;
}
section h1 {
font-size: 100px;
font-weight: 420;
position: absolute;
top: 130px;
left: 200px;
opacity: 0;
transform: translateY( 43px );
animation-name: fade-in;
animation-duration: 0.6s;
animation-timing-function: ease-out;
animation-fill-mode: forwards;
}
var currentIndex = 0;
var hello = new Array( 'Hello', 'Bonjour', 'Hola' );
function randomIndex( ) {
return Math.floor( Math.random( ) * hello.length);
};
window.setInterval( function( ) {
var newIndex = randomIndex( );
while( newIndex === currentIndex ) newIndex = randomIndex();
currentIndex = newIndex;
document.getElementById("switch").textContent = hello[ currentIndex ];
}, 2300 );
【问题讨论】:
标签: javascript html jquery css frontend