以下是如何在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中文網其他相關文章!