When writing an h5 canvas game, the position of the button clicked changed after the screen was adapted.

Today, when I played an h5 game, after adapting, the size of the canvas changed, but some buttons inside found that they could not be clicked, and only when they clicked somewhere else could they react. What is the reason for this?

Mar.10,2021

To achieve the click effect on

canvas , it must be achieved by calculating the click position.
and after you have adapted, if you want to click on the hot area remains the same, you need to get your standard width and height and the width and height of the current page to calculate, get the correct zoom ratio, and then modify the click on the hot area.

something like this:

const standardWidth = 1920

let widthScaleRatio = window.screen.availWidth / standardWidth

let triggerXRange = [0, 800]
$canvas.click(e => {
  if (e.clientX >= triggerXRange[0] * widthScaleRatio && e.clientX <= triggerXRange[1] * widthScaleRatio) {
    console.log('trigger')
  }
})
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-1ea5b8a-1d7b.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-1ea5b8a-1d7b.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
Need Help?