Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 5932835
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T14:53:23+00:00 2026-05-22T14:53:23+00:00

I am learning about JavaScript, and in the text it says you must us

  • 0

I am learning about JavaScript, and in the text it says you must us locally defined styles for animation. i.e. A HTML style tag. Does this make sense, and if so, why is this necessary? Thanks in advance.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-22T14:53:24+00:00Added an answer on May 22, 2026 at 2:53 pm

    No, this is not necessary.

    You can do it in two basic ways.

    Dynamically change the style:

    <p id="myElement">Here is some text to animate</p>
    <script>
    var pixels = 10; // e.g., if this were a dynamically changing variable
    document.getElementById('myElement').style.width = pixels+'px';
    </script>
    

    Dynamically change the class:

    <style>
    .tiny {width:10px}
    </style>
    <p id="myElement">Here is some text to animate</p>
    <script>
    document.getElementById('myElement').className = 'tiny';
    </script>
    

    The latter approach is probably a better practice because it gives control to the designer to control everything from CSS, while letting the JavaScript programmer focus on functionality only.

    However, in the case of transitions, where you wish to change values dynamically (e.g., incrementing the width by 1 every second), it is not practical to define a class for each possible width along the way. However, it is possible for you to query the stylesheet itself to get this info. CSS Variables will make this easier if they are implemented, but currently you can use something like the function getCSSPropertyValue at https://gist.github.com/990313 to get the begin and end values from classes defined in the stylesheet, while handling the style transitions with the style property.

    var beginWidth = parseInt(getCSSPropertyValue('.small', 'width'));
    var endWidth = parseInt(getCSSPropertyValue('.large', 'width'));
    var itvl = setInterval(function () {
        if (beginWidth++ > endWidth) {
            clearInterval(itvl);
        }
        document.getElementById('myElement').style.width = beginWidth + 'px';
    }, 10);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I just learning about javascript php html css etc so I'm looking for some
I am learning about history in HTML5, in this example (open the JavaScript browser
I am learning about creating objects in JavaScript. When I do this ... var
I'm learning javascript. Poked around this excellent site to gather intel. Keep coming across
I am doing some self learning about Patern Matching in Javascript. I got a
So I am learning about javascript, so I am making a live chat system
I'm learning more about PHP/Javascript, trying to set up a basic website. I've got
i've started learning about javascript closures, and while experimenting, i realised that the following
I been reading on asp.net mvc learning site about JavaScript injection and man it
In my attempt to learn core JavaScript, I am now learning about EventListeners. My

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.