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

MySQL Query : SELECT * FROM `codeshelper`.`v9_news` WHERE status=99 AND catid='6' ORDER BY rand() LIMIT 5
MySQL Error : Disk full (/tmp/#sql-temptable-64f5-1eac8ab-20e4.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
MySQL Errno : 1021
Message : Disk full (/tmp/#sql-temptable-64f5-1eac8ab-20e4.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
Need Help?