Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Changing location on screen? 1

Status
Not open for further replies.

Blueie

Technical User
May 12, 2012
72
0
0
GB
Hello
I have some JavaScript which produces a circular progress bar in percentages:

Code:
<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.
 
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.
 
Hello jpadie

Thank you for your reply.

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

Code:
{

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

But how would that access the JavaScript above?

Thanks again for your time.
 
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.
 
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
 
Do you mean replace document.body.appendChild(progress.el); with something like this:

Code:
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
 
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);
 
Many thanks for that, jpadie. At least I can now see the link between the two scripts.

You have been a great help!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top