Forums

The forums ran from 2008-2020 and are now closed and viewable here as an archive.

Home Forums JavaScript 100% canvas area problem

  • This topic is empty.
Viewing 2 posts - 1 through 2 (of 2 total)
  • Author
    Posts
  • #197728
    Jerba
    Participant

    I’m currently working on the a cliche Javascript particle system. However, I’m working to a canvas with an area set to that of the users window.

    Despite the size of the canvas, the value of the width and height are returned as 0, which very much becomes and issue when I’m trying to draw to random positions within the canvas.

    particle {particle_x: 0, particle_y: 0, particle_size: 2, particle_color: "rgb(211,121,11);"}
    particle {particle_x: 0, particle_y: 0, particle_size: 6, particle_color: "rgb(51,108,134);"}
    particle {particle_x: 0, particle_y: 0, particle_size: 6, particle_color: "rgb(193,165,42);"}
    particle {particle_x: 0, particle_y: 0, particle_size: 5, particle_color: "rgb(231,26,18);"}

    Here’s the code on codepen (You will need to edit and check the console to see the debugging)
    http://codepen.io/Responsive/pen/bNxzGJ

    So is there anyway, I can maintain the 100% area, but have the width and height return a value in pixels?

    Thanks for any help!

    #197732
    Senff
    Participant

    I don’t think window.width returns anything proper. Perhaps window.innerWidth is what you meant?

Viewing 2 posts - 1 through 2 (of 2 total)
  • The forum ‘JavaScript’ is closed to new topics and replies.