JavaScriptでタイピング効果を作成するにはどうすればよいですか?
JavaScriptでタイピング効果を作成するには、コードは次のとおりです-
例
<!DOCTYPE html>
<html>
<head>
<style>
body{
font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
}
button{
padding:10px;
font-size: 18px;
background-color: rgb(128, 19, 218);
color:white;
border:none;
}
.heading{
color:crimson;
}
</style>
</head>
<body>
<h1>typeText</h1>
<button class="typeButton">Click me</button>
<h2 class="heading"></h2>
<script>
document.querySelector('.typeButton').addEventListener('click',typeText);
var i = 0;
var text = 'This text is currently being typed across... It is still typing..';
var speed = 50;
function typeText() {
if (i < text.length) {
document.querySelector('.heading').innerHTML += text.charAt(i);
i++;
setTimeout(typeText, speed);
}
}
</script>
</body>
</html> 出力
上記のコードは次の出力を生成します-
「クリックしてください」をクリックすると 」ボタン-
-
JavaScriptとCSSを使用したエフェクトの入力と削除
CSSアニメーションの助けを借りて、JavaScriptを使用してタイプライターの入力および削除効果を作成できます。 次の例は、この効果を示しています。 例 <!DOCTYPE html> <html> <style> div { display: flex; margin: 4%; padding: 2%; box-shadow: inset 0 0 12px blue; } p { font-family: "Co
-
CSSでオーバーレイ効果を作成するにはどうすればよいですか?
CSSでオーバーレイ効果を作成するには、コードは次のとおりです- 例 <!DOCTYPE html> <html> <head> <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.7.0/css/fontawesome.min.css"> <style> body { font-family: Arial; } &n