The width obtained using jquery's prop ('width') is different from the actual width.

the element width obtained by using jquery"s prop ("width") method is different from the actual width.
there is no need to change the browser window size in the middle

Apr.03,2021

prop reads the width attribute of the element, not necessarily the width
, which is similar to width (), should be

.
$('-sharpcolor_box).css("width")

prop () is used to set or get the attribute on the specified DOM element object
attr () is used to set or get the attribute on the document node corresponding to the specified DOM element


prop ('width') gets the value of the width attribute you set in the html tag . The premise of getting the value is that the attribute width has been assigned (or has its own default value, such as canvas), must also require that this html element is born with this attribute , otherwise it cannot be obtained: for example, div cannot be obtained even if it is set, table, td, canvas, etc.).
width () gets the actual width of the content area , that is, the width excluding border,padding

so, you will find that the values of the two are not the same.

in this example, after communicating with the questioner, the canvas, used for the scene does not set the attribute width, according to W3 standard , the default width of Canvas is 300 , and the height is 150

.

clipboard.png

Menu