Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <!DOCTYPE html>
- <html lang="en">
- <head>
- <link rel="shortcut icon" href="https://1xpto.netlify.app/items/favicon.gif" type="image/x-icon">
- <meta charset="UTF-8">
- <meta http-equiv="X-UA-Compatible" content="IE=edge">
- <meta name="keywords" content="loop,typewriter,effect,media">
- <meta name="viewport" content="width=device-width, initial-scale=1.0">
- <title>Looping typewriter effect</title>
- <style>
- button {
- border: 0;
- outline: 0;
- background-color: red;
- color: white;
- position: fixed;
- top: 0;
- left: 0;
- margin: 5px;
- padding: 5px 20px;
- font-size: 20px;
- }
- body {
- margin: 0;word-wrap: break-word;
- }
- p {
- font-family: calibri;
- font-weight: bold;
- text-align: justify;
- font-size: 2vw;
- padding: 100px 20px 20px 20px;
- }
- @media all and (orientation:portrait) {
- p {
- font-size: 16px;
- width: 90%;
- margin: auto;
- padding: 100px 0 20px 0;
- }
- }
- @media all and (orientation:landscape) and (max-width:768px) {
- p {
- font-size: 16px;
- width: 90%;
- margin: auto;
- padding: 100px 0 20px 0;
- }
- }
- </style>
- </head>
- <body>
- <button onclick='stoploop()'>Stop Loop</button>
- <p></p>
- <h1>
- <script>
- text = document.getElementsByTagName('h1')[0].innerHTML;
- length = text.length;
- p = document.getElementsByTagName('p')[0];
- i = 0;
- x = setInterval(foo, 1000 / 60);
- function foo() {
- p.innerHTML += text[i];
- i++;
- window.scrollBy(0, 100);
- if (i == length) {
- i = 0;
- foo();
- }
- }
- (stoploop = () => {
- clearInterval(x);
- })
- </script>
- </body>
- </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement