Typing Text Auto Type Simple Animation Using Only html css and Javascript
<html lang="en">
<head>
<!-- Required meta tags -->
<title>Codekarnedo.com | Typing Text Auto Type Simple Animation Using Only html css and Javascript</title>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
<style type="text/css">
</style>
<link rel="stylesheet" type="text/css" href="css/style.css">
</head>
<body>
<h2>Typing Text Auto Type Simple Animation Using Only html css and Javascript</h2>
<!-- start from -->
<div class="typewriter-box">
<p id="the-typing-text" class="the-typing-text"></p>
</div>
<script src="js/js.js"></script>
</body>
</html>
.the-typing-text {
display: inline-block;
overflow: hidden;
border-right: 0.20em solid #ff5d7d;
font-family: monospace;
font-size: 18px;
font-weight: 700;
opacity: .9;
transition: opacity 0.4s ease-in-out;
}
/* Cursor blink effect */
@keyframes simple-blink-caret {
from, to { border-color: transparent;}
50% {border-color: #ff5d7d;}
}
.the-typing-text.typing {
opacity: 1;
animation: simple-blink-caret 0.75s step-end infinite;}
document.addEventListener('DOMContentLoaded', () => {
const text = "Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum."; // Text to be typed
const typingSpeed = 100; // Typing speed in milliseconds
const typingTextElement = document.getElementById('the-typing-text');
// Function to type the text character by character
function typeText() {
let index = 0;
function typeCharacter() {
if (index < text.length) {
typingTextElement.textContent += text.charAt(index); // Add one character at a time
index++;
setTimeout(typeCharacter, typingSpeed); // Delay between each character
}
}
typeCharacter();
}
// Observer options
const options = {
root: null, // Use the viewport as the container
rootMargin: '0px',
threshold: 0.1 // Trigger when 10% of the section is visible
};
// Callback function for the observer
const callback = (entries, observer) => {
entries.forEach(entry => {
if (entry.isIntersecting) {
typingTextElement.classList.add('typing'); // Add typing class for CSS effects
typeText(); // Start the typing animation
observer.unobserve(entry.target); // Stop observing once animation starts
}
});
};
// Create the observer
const observer = new IntersectionObserver(callback, options);
observer.observe(document.querySelector('.typewriter-box')); // Observe the section
});
Comments (0 )
Leave A Comment