JavaScript - Simple Textbox AutoScroll Animation

In this tutorial we will create a Simple Textbox AutoScroll Animation using Javascript. JavaScript is a scripting or programming language that allows you to implement complex things on web pages. It is a text-based programming language meant to run as part of a web-based application. It is an interpreted programming language that has a capabilities of Object-Oriented. So Let's do the coding...

Getting started:

This is the link for the bootstrap that i used for the layout design

The Main Interface

This code contains the interface of 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. <meta charset="UTF-8" name="viewport" content="width=device-width, initial-scale=1"/>
  5. <link rel="stylesheet" type="text/css" href="css/bootstrap.css"/>
  6. </head>
  7. <nav class="navbar navbar-default">
  8. <div class="container-fluid">
  9. <a class="navbar-brand">Sourcecodester</a>
  10. </div>
  11. </nav>
  12. <div class="col-md-3"></div>
  13. <div class="col-md-6 well">
  14. <h3 class="text-primary">JavaScript - Simple Textbox AutoScroll Animation</h3>
  15. <hr style="border-top:1px dotted #ccc;"/>
  16. <div class="col-md-3"></div>
  17. <div class="col-md-6">
  18. <form>
  19. <div class="form-group">
  20. <input name="text" class="form-control" id="text" value="" disabled />
  21. </div>
  22. <center><button class="btn btn-primary" id="play" type="button" onclick="animateText(this);">Animate</button> <button class="btn btn-danger" id="stop" type="button" onclick="stopAnim(this);" disabled="disabled">Stop</button></center>
  23. </form>
  24. </div>
  25. </div>
  26. <script src="js/script.js"></script>
  27. </body>
  28. </html>

Creating the Script

This code contains the script of the application. This code will animate the input text box when the button is clicked. To do this just copy and write these block of codes as shown below inside the text editor and save it as script.js inside the js folder.
  1. initialize();
  3. function initialize(){
  4. speed = 180
  5. chars = 1
  6. var timer;
  7. var text = "The quick brown fox jumps over the lazy dog. ";
  8. document.getElementById('text').value = text;
  9. }
  11. function animateText(btn) {
  12. timer = window.setTimeout('animateText()',speed);
  13. var msg = document.getElementById('text').value;
  14. document.getElementById('text').value =
  15. msg.substring(chars) +
  16. msg.substring(0,chars);
  18. btn.setAttribute("disabled", "disabled");
  19. document.getElementById('stop').removeAttribute("disabled");
  20. }
  22. function stopAnim(btn){
  23. clearTimeout(timer);
  25. btn.setAttribute("disabled", "disabled");
  26. document.getElementById('play').removeAttribute("disabled");
  27. }
There you have it we successfully created a Simple Textbox AutoScroll 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