INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Jobs

Changing location on screen?

Changing location on screen?

(OP)
Hello
I have some JavaScript which produces a circular progress bar in percentages:

CODE --> JS

<script src="../circular-progress.js"></script>
   
(function () {
      var n, id, progress;

      progress = new CircularProgress({
        radius: 20
      });

      document.body.appendChild(progress.el);

      n = 0;
      id = setInterval(function () {
        if (n == 100) clearInterval(id);
        progress.update(n++);
      }, 100);
    })();

    (function () {
      var n, id, progress;

      progress = new CircularProgress({
        radius: 40,
        lineWidth: 2,
        strokeStyle: 'black',
        initial: {
          lineWidth: 4,
          strokeStyle: 'gray'
        }
      });

      document.body.appendChild(progress.el);

      n = 0;
      id = setInterval(function () {
        if (n == 100) clearInterval(id);
        progress.update(n++);
      }, 70);
    })();

    (function () {
      var n, id, progress;

      progress = new CircularProgress({
        radius: 70,
        strokeStyle: 'black',
        lineCap: 'square',
        lineJoin: 'round',
        lineWidth: 5,
        shadowBlur: 0,
        shadowColor: 'yellow',
        text: {
          font: 'bold 15px arial',
          shadowBlur: 0
        },
        initial: {
          strokeStyle: 'white',
          lineCap: 'square',
          lineJoin: 'round',
          lineWidth: 5,
          shadowBlur: 10,
          shadowColor: 'black'
        }
      });

      document.body.appendChild(progress.el);

      n = 0;
      id = setInterval(function () {
        if (n == 100) clearInterval(id);
        progress.update(n++);
      }, 30);
    })(); 

Apparently, I am unable to add CSS style to the script but I can change the colours, etc. Is there a way also of changing its location on my Web page and, if so, how would I do that, please?

Thank you.

RE: Changing location on screen?

why are you creating so many progress variables?

to position the output, instead of appending it to body, append it to a div whose position you have preset absolutely.

RE: Changing location on screen?

(OP)
Hello jpadie

Thank you for your reply.

I can place this in my CSS to position the circular progress bar:

CODE --> JS

{

position: fixed;
top: 150px;
left: 300px;
} 

But how would that access the JavaScript above?

Thanks again for your time.

RE: Changing location on screen?

You are appending the progress bar to document.body. instead append it to a div which is positioned where you want.

In you are saying that the plugin you use cab sort the positioning out for you by including those directives in the constructor then you have solved the problem yourself.

RE: Changing location on screen?

Quote:

But how would that access the JavaScript above?

It doesn't, javascript does the 'accessing' of CSS styles, not the other way around.

Chris.

Indifference will be the downfall of mankind, but who cares?
Time flies like an arrow, however, fruit flies like a banana.
Webmaster Forum

RE: Changing location on screen?

(OP)
Do you mean replace document.body.appendChild(progress.el); with something like this:

CODE --> JS

myPosition.appendChild(progress.el);

<style>
.myPosition {

top: 100px;
left: 300px;
}
</style> 

Sorry, I don't know anything about JavaScript. I contacted the author of the script and he was pleased I was hoping to use it but not wonderfully helpful.

Blueie

RE: Changing location on screen?

let us say you have a positioned div where you want it and with the id 'myDiv'

instead of

CODE

document.body.appendChild(progress.el); 
you would use

CODE

document.getElementById('myDiv').appendChild(progress.el); 

RE: Changing location on screen?

(OP)
Many thanks for that, jpadie. At least I can now see the link between the two scripts.

You have been a great help!

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members!

Resources

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close