• We just launched and are currently in beta. Join us as we build and grow the community.

Javascript - Simple Text Animation

6o6

Ad Campaign Expert
6 Rep
0
0
0
Rep
0
6 Vouches
0
0
0
Vouches
0
Posts
85
Likes
82
Bits
2 MONTHS
2 2 MONTHS OF SERVICE
LEVEL 1 300 XP
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 https://getbootstrap.com/

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. <body

    >
  8. <nav class

    =

    "navbar navbar-default"

    >
  9. <div

    class

    =

    "container-fluid"

    >
  10. <a

    class

    =

    "navbar-brand"

    href

    =

    "https://sourcecodester"

    >

    Sourcecodester</

    a

    >
  11. </

    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"

    ]

  7. display.style

    .fontSize

    =

    size +

    "px"

    ;
  8. display.style

    .color

    =

    color;
  9. font.value

    =

    size;
  10. data.onkeyup

    =

    function

    (

    )

    {
  11. display.innerHTML

    =

    inputText.value

    ;
  12. }

  13. function

    increaseFont(

    )

    {
  14. size++;
  15. display.style

    .fontSize

    =

    size +

    "px"

    ;
  16. font.value

    =

    size;
  17. }

  18. function

    decreaseFont(

    )

    {
  19. size--;

  20. if

    (

    size <

    1

    )

    {
  21. size =

    1

    ;
  22. }

  23. display.style

    .fontSize

    =

    size +

    "px"

    ;
  24. font.value

    =

    size;
  25. }

  26. function

    changeColor(

    )

    {
  27. var

    rand =

    arrayColor[

    Math

    .floor

    (

    Math

    .random

    (

    )

    *

    arrayColor.length

    )

    ]

    ;
  28. display.style

    .color

    =

    rand;
  29. }

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!!


Download
You must upgrade your account or reply in the thread to view hidden text.
 

450,270

322,965

322,974

Top