Stop sequence of letters while hovering using javascript

 


Youtube link - click here

Source code :

<!DOCTYPE html>
<html>

<head>
    <title>
        stop letters while hovering
    </title>
    <style>
        #display {
            font-size: 50px;
        }
       
        #display {
            background-color: black;
            color: white;
        }
    </style>
</head>

<body>
    <button onclick="clk()">click to start</button>
    <p id="display"></p>
    <script>
        var text = "Monster";
        var i = 0;

        function clk() {
            var time = setInterval(function() {
                var font = text[i];
                document.getElementById('display').innerHTML = font;
                i++;
                if (i == text.length) {
                    i = 0;
                }
            }, 200);
            document.getElementById("display").onmouseover = function() {
                clearInterval(time);
            }
            document.getElementById('display').onmouseout = function() {
                clk();
            }
        }
    </script>
</body>

</html>

Post a Comment

Post a Comment (0)

Previous Post Next Post