Artifacts Gallery Guilds Search Wiki Login Register

Welcome, Guest. Please login or register. - Thinking of joining?
Autumn, 28 Oct 2026 - @604.29
Forum Activity: Four Stars Random | Recent Posts | Guild Recents
News: ozwomp is requesting your location :ozwomp: [Agree] Guild Events: Halloween Watch-a-thon
Super News: ~~MelonLand's Halloween Profile Design Contest 2026~~
+  MelonLand Forum
|-+  Da Web Revival
| |-+  ✁ ∙ Web Crafting
| | |-+  ☔︎ ∙ I need Help!
| | | |-+  Canvas / JS help needed


« previous next »
Pages: [1] Print Embed
Author Topic: Canvas / JS help needed  (Read 981 times)
Skykristal
Sr. Member ⚓︎
****
View Profile WWWArt


I may be dead but I am here
⛺︎ My Room
SpaceHey: Friend Me!
StatusCafe: skykristal
iMood: skykristal

Guild Memberships:
Artifacts:
Uni-StarFirst 1000 Members!Great Posts PacmanJoined 2023!
« on: Spring, 04 Apr 2025 @882 » Toggle Font Embed

I need help resizing my canvas (my drawbox). Its set to 500px by 500px in the HTML which is too big for mobile screen/version and its also not aligning with my other boxes. When I edit the numbers the canvas acts weird and the background is gone.

Applying 100% width in CSS to canvas does exactly what I want visually but creates displacement of the drawn strokes.
I don't understand JS and googling it doesn't help me at all. I don't know what to add to my current js file for my specific project. Please don't explain it to me with words and terms, I don't understand it...  :sad:

drawbox is located here
https://skykristal.art/CoolStuff/

JS file
https://skykristal.art/CoolStuff/drawboxjs.js

I'd appreciate some help with this. thank you

Logged

https://skykristal.art/Ocs/_rebecka.pnghttp://internetometer.com/imagesmall/50425.png https://skykristal.art/CoolStuff/_aquarium-icon.png https://skykristal.art/CoolStuff/_tobi-icon.png https://skykristal.art/CoolStuff/_flora-icon.png https://skykristal.art/CoolStuff/_toothy-icon.png
Melooon
Hero Member ⚓︎
*****
View Profile WWWArt


So many stars!
⛺︎ My Room
SpaceHey: Friend Me!
StatusCafe: melon
iMood: Melonking
Itch.io: My Games
RSS: RSS

Guild Memberships:
Artifacts:
Caught by RubbereonYou're a Star!Flinstone VitaminWavy Shoulder-Length Hair with BangsBug!Top Hat
« Reply #1 on: Spring, 04 Apr 2025 @894 » Toggle Font Embed

The script seems to depend on a fixed width/height for the canvas, and it uses whatever size the canvas is when it first loads (it should work for any size you set on the canvas style from what I can see, as long as that style is applied before the script is loaded) - when you draw, you're basically mapping pixels into a pixel grid thats the size of the canvas so it would not be possible to make it dynamically resize without VAST rewrites to the code to resize your drawing (or at least without making the canvas reset each time its resized)

I'd suggest the best solution would be to simply pick a fixed size and work around that. You could do some trickery to make the canvas zoom by modifying its scale transform in relation to your overall page width, but that might require scripting too and could be pretty complex to figure out as well! You could also put the drawbox in an overflowing iframe, but that might be weird!

Logged


everything lost will be recovered, when you drift into the arms of the undiscovered

Artifact Swap: Have a chillpillRed Tulip
Skykristal
Sr. Member ⚓︎
****
View Profile WWWArt


I may be dead but I am here
⛺︎ My Room
SpaceHey: Friend Me!
StatusCafe: skykristal
iMood: skykristal

Guild Memberships:
Artifacts:
Uni-StarFirst 1000 Members!Great Posts PacmanJoined 2023!
« Reply #2 on: Spring, 04 Apr 2025 @899 » Toggle Font Embed

The script seems to depend on a fixed width/height for the canvas, and it uses whatever size the canvas is when it first loads (it should work for any size you set on the canvas style from what I can see, as long as that style is applied before the script is loaded) - when you draw, you're basically mapping pixels into a pixel grid thats the size of the canvas so it would not be possible to make it dynamically resize without VAST rewrites to the code to resize your drawing (or at least without making the canvas reset each time its resized)

I'd suggest the best solution would be to simply pick a fixed size and work around that. You could do some trickery to make the canvas zoom by modifying its scale transform in relation to your overall page width, but that might require scripting too and could be pretty complex to figure out as well! You could also put the drawbox in an overflowing iframe, but that might be weird!

I would love to set a different fixed width/height (generally just making it a little smaller) but Like I mentioned, it erases the background (makes it transparent). I don't know much, but from what I understand when reading the script, it reads the width and hight specified in the HTML. which is 500px atm. idk why its doing that.

Also what does "style is applied before the script is loaded" mean? its placed at the very bottom of my HTML.. idk is that what you mean?

Logged

https://skykristal.art/Ocs/_rebecka.pnghttp://internetometer.com/imagesmall/50425.png https://skykristal.art/CoolStuff/_aquarium-icon.png https://skykristal.art/CoolStuff/_tobi-icon.png https://skykristal.art/CoolStuff/_flora-icon.png https://skykristal.art/CoolStuff/_toothy-icon.png
Melooon
Hero Member ⚓︎
*****
View Profile WWWArt


So many stars!
⛺︎ My Room
SpaceHey: Friend Me!
StatusCafe: melon
iMood: Melonking
Itch.io: My Games
RSS: RSS

Guild Memberships:
Artifacts:
Caught by RubbereonYou're a Star!Flinstone VitaminWavy Shoulder-Length Hair with BangsBug!Top Hat
« Reply #3 on: Spring, 04 Apr 2025 @902 » Toggle Font Embed

it erases the background (makes it transparent).
It's not doing this for me; I can set the canvas to 300px wide and tall and it works perfectly! :ohdear:
Code
<canvas id="drawboxcanvas" width="300px" height="300px"></canvas>

its placed at the very bottom of my HTML
Yes this means your doing it correctly :grin:

Logged


everything lost will be recovered, when you drift into the arms of the undiscovered

Artifact Swap: Have a chillpillRed Tulip
Skykristal
Sr. Member ⚓︎
****
View Profile WWWArt


I may be dead but I am here
⛺︎ My Room
SpaceHey: Friend Me!
StatusCafe: skykristal
iMood: skykristal

Guild Memberships:
Artifacts:
Uni-StarFirst 1000 Members!Great Posts PacmanJoined 2023!
« Reply #4 on: Spring, 04 Apr 2025 @907 » Toggle Font Embed

It's not doing this for me; I can set the canvas to 300px wide and tall and it works perfectly! :ohdear:
Code
<canvas id="drawboxcanvas" width="300px" height="300px"></canvas>
okay VERY strange. It worked now. I tested this several times before... that's why I was so lost  :skull: browser bug?? but man that's awesome.

Quote
Yes this means your doing it correctly :grin:
ooooh okay. I get it now!

Thank you so much for helping me out  :4u: 

Logged

https://skykristal.art/Ocs/_rebecka.pnghttp://internetometer.com/imagesmall/50425.png https://skykristal.art/CoolStuff/_aquarium-icon.png https://skykristal.art/CoolStuff/_tobi-icon.png https://skykristal.art/CoolStuff/_flora-icon.png https://skykristal.art/CoolStuff/_toothy-icon.png
Pages: [1] Print Embed 
« previous next »
 

Melonking.Net © Always and ever was! SMF 2.0.19 | SMF © 2021 | Privacy Notice | Send Feedback | Supporters ♥ Forum Guide | Rules | RSS | WAP | Mobile


MelonLand Badges and Other Melon Sites!

MelonLand Project! Visit the MelonLand Forum! Support the Forum
Visit Melonking.Net! Visit the Gif Gallery! Pixel Sea TamaNOTchi
@000 Melon
Land
Forum Art Hub Chat Webring Explore Random Recent Tenement Arcade Want to Login or Join ? Web Craft Guide Graphic Catalogue Wiki Help I'm Lost! Link Land Newsletters Image Stream Minecraft: Online
Zap!
Passport Sites tamaNOTchi Asatte Add your site?
Aero Archive Onio Cafe 32 Bit Cafe Status Cafe