我是JavaScript的新手。我发现了一个缩放图像的代码。我的问题是如何在下面的JavaScript代码中添加pinch事件,以便图像根据捏合进行缩放?
这是HTML代码
<html>
<body>
<map id="map" name="map">
<area coords="15,92,568,247" alt="Blah" href="javascript:alert('hello');" />
<area coords="18,259,546,432" alt="Blah" href="javascript:alert('hello 2');" />
</map>
<input type="button" value="+" onclick="javascript:ZoomIn();"/>
<input type="button" value="-" onclick="javascript:ZoomOut();"/><br />
<img src="Highlight cells.png" usemap="#map" id="image" />
Javascript代码
function ZoomIn() {
Zoom(1.1);
}
function ZoomOut() {
Zoom(0.9);
}
function Zoom(amount) {
// resize image
var image = document.getElementById('image');
image.height = image.height * amount;
// resize image map
var map = document.getElementById('map');
for (var i = 0; i < map.areas.length; i++) {
var area = map.areas[i];
var coords = area.coords.split(',');
for (var j = 0; j < coords.length; j++) {
coords[j] = coords[j] * amount;
}
area.coords = coords[0] + ',' + coords[1] + ',' + coords[2] + ',' + coords[3];
}
}