Entrance Events! Chat Gallery Search Everyone Wiki Login Register

Welcome, Guest. Please login or register. - Thinking of joining the forum??
April 08, 2025 - @788.53 (what is this?)
Activity rating: Three Stars Posts & Arts: 48/1k.beats Unread Topics | Unread Replies | My Stuff | Random Topic | Recent Posts Start New Topic  Submit Art
News: :happy:  :pc: There are community newsletters here! :pc: :happy: Super News: Upload a banner!

+  MelonLand Forum
|-+  World Wild Web
| |-+  ✁ ∙ Web Crafting
| | |-+  ☔︎ ∙ I need Help!
| | | |-+  Canvas / JS help needed


« previous next »
Pages: [1] Print
Author Topic: Canvas / JS help needed  (Read 72 times)
Skykristal
Full Member ⚓︎
***


I may be dead but I am here

⛺︎ My Room
StatusCafe: skykristal

View Profile WWWArt

Great Posts PacmanFirst 1000 Members!Joined 2023!
« on: April 04, 2025 @882.25 »

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


Read My Blog ⋆。°✩ Punch my OCs  ⋆。°✩ View my Gallery


Melooon
Hero Member ⚓︎
*****


So many stars!

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

View Profile WWWArt

Hyperactive DonutGreat Posts PacmanOfficially DogThanks for being rad!a puppy for your travelsAlways My Pal
« Reply #1 on: April 04, 2025 @894.19 »

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
Skykristal
Full Member ⚓︎
***


I may be dead but I am here

⛺︎ My Room
StatusCafe: skykristal

View Profile WWWArt

Great Posts PacmanFirst 1000 Members!Joined 2023!
« Reply #2 on: April 04, 2025 @898.61 »

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


Read My Blog ⋆。°✩ Punch my OCs  ⋆。°✩ View my Gallery


Melooon
Hero Member ⚓︎
*****


So many stars!

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

View Profile WWWArt

Hyperactive DonutGreat Posts PacmanOfficially DogThanks for being rad!a puppy for your travelsAlways My Pal
« Reply #3 on: April 04, 2025 @902.25 »

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
Skykristal
Full Member ⚓︎
***


I may be dead but I am here

⛺︎ My Room
StatusCafe: skykristal

View Profile WWWArt

Great Posts PacmanFirst 1000 Members!Joined 2023!
« Reply #4 on: April 04, 2025 @906.52 »

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


Read My Blog ⋆。°✩ Punch my OCs  ⋆。°✩ View my Gallery


Pages: [1] Print 
« previous next »
 

Vaguely similar topics! (3)

Melons critiquing and helping each other

Started by urgellxBoard ✎ ∙ Art Crafting

Replies: 22
Views: 2548
Last post August 24, 2024 @487.13
by e-
Plastic Canvas Fursuit Heads

Started by OneMillionFurriesBoard ✎ ∙ Art Crafting

Replies: 1
Views: 740
Last post February 02, 2024 @166.05
by Rico
What helped you code html/css easy?

Started by LIABoard ✁ ∙ Web Crafting

Replies: 17
Views: 2654
Last post October 11, 2023 @152.56
by flowers

Melonking.Net © Always and ever was! SMF 2.0.19 | SMF © 2021 | Privacy Notice | ~ Send Feedback ~ 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