以下是如何在 JavaScript 中实现此解决方案的示例:
// Canvas element var canvas = document.getElementById('myCanvas'); // Drawing context var hdc = canvas.getContext('2d'); // Event listeners for (var i = 0; i < areas.length; i++) { areas[i].addEventListener('mouseover', function() { var coords = this.getAttribute('coords'); hdc.beginPath(); hdc.moveTo(coords[0], coords[1]); for (var j = 2; j < coords.length; j += 2) { hdc.lineTo(coords[j], coords[j+1]); } hdc.lineTo(coords[0], coords[1]); hdc.stroke(); }); areas[i].addEventListener('mouseout', function() { hdc.clearRect(0, 0, canvas.width, canvas.height); }); }
以上是如何用画布轮廓突出显示图像地图区域?的详细内容。更多信息请关注PHP中文网其他相关文章!