Javascript - Simple Text Animation

Submitted by: 
Visitors have accessed this post 311 times.

In this tutorial we will create a Simple Text Animation using Javascript. JavaScript is a scripting or programming language that allows you to implement complex things on web pages. It is widely used in designing a stunning website. It is an interpreted programming language that has a capabilities of Object-Oriented. This code can be used as your calculator to any mathematical problem. So Let's do the coding.

Before we started:

This is the link for the bootstrap that has been used for the layout of the calculator

The Main Interface

This code contains the interface of the application. This will display the text that will be needed to animate within the application. To create this just write these block of code inside the text editor and save this as index.html.

  1. <!DOCTYPE html>
  2. <html lang="en">
  3. <head>
  4. <link rel="stylesheet" type="text/css" href="css/bootstrap.css"/>
  5. <meta charset="UTF-8" name="viewport" content="width=device-width, initial-scale=1"/>
  6. </head>
  7. <nav class="navbar navbar-default">
  8. <div class="container-fluid">
  9. <a class="navbar-brand" href="<a href="https://sourcecodester">Sourcecodester</a>
  10. " rel="nofollow">https://sourcecodester">Sourcecodester</a>
  11. </a> </div>
  12. </nav>
  13. <div class="col-md-3"></div>
  14. <div class="col-md-6 well">
  15. <h3 class="text-primary">Javascript - Simple Text Animation</h3>
  16. <hr style="border-top:1px dotted #ccc;"/>
  17. <div class="col-md-2"></div>
  18. <div class="col-md-8">
  19. <label>Enter a text</label>
  20. <input type="text" name="text" id="inputText" style="width:140px;"/>
  21. <button class="btn btn-primary" onclick="decreaseFont()"><span class="glyphicon glyphicon-minus"></span></button>
  22. <input type="text" id="size" style="width:50px;" disabled = "disabled"/>
  23. <button class="btn btn-primary" onclick="increaseFont()"><span class="glyphicon glyphicon-plus"></span></button>
  24. <br /><br />
  25. <center><button class="btn btn-success" onclick="changeColor()">Change Color</button></center>
  26. <br /><br /><br />
  27. <center><label id="display"></label></center>
  28. </div>
  29. </div>
  30. </body>
  31. <script src="script.js"></script>
  32. </html>

Creating the Script

This code contains the script of the application. To do this just copy and write these block of codes as shown below inside the text editor and save it as script.js.

  1. var size = 14;
  2. var color = "#000000"
  3. var data = document.getElementById("inputText");
  4. var display = document.getElementById('display');
  5. var font = document.getElementById('size');
  6. var arrayColor=["#FF0000", "#00FF00", "#0000FF", "#FFFF00", "#000000"]
  8. size + "px";
  10. font.value = size;
  11. data.onkeyup = function(){
  12. display.innerHTML = inputText.value;
  13. }
  15. function increaseFont(){
  16. size++;
  17. size + "px";
  18. font.value = size;
  19. }
  21. function decreaseFont(){
  22. size--;
  24. if(size < 1){
  25. size = 1;
  26. }
  28. size + "px";
  29. font.value = size;
  30. }
  32. function changeColor(){
  33. var rand = arrayColor[Math.floor(Math.random() * arrayColor.length)];
  35. }

There you have it we successfully created a Simple Text Animation using Javascript. I hope that this simple tutorial help you to what you are looking for. For more updates and tutorials just kindly visit this site. Enjoy Coding!!

Add new comment

Filtered HTML

  • Web page addresses and e-mail addresses turn into links automatically.
  • You may insert videos with [video:URL]
  • Allowed HTML tags: <a> <em> <strong> <cite> <blockquote> <code> <ul> <ol> <li> <dl> <dt> <dd> <table> <tr> <td> <th> <img> <h1> <h2> <h3> <iframe> [video]
  • You can enable syntax highlighting of source code with the following tags: <code>, <blockcode>, <asp>, <c>, <cpp>, <csharp>, <css>, <html4strict>, <java>, <javascript>, <mysql>, <php>, <python>, <sql>, <vb>, <vbnet>. The supported tag styles are: <foo>, [foo].
  • Lines and paragraphs break automatically.

Plain text

  • No HTML tags allowed.
  • Lines and paragraphs break automatically.
This question is for testing whether or not you are a human visitor and to prevent automated spam submissions.