Hello out there!
Ich erstelle dynamisch eine Image-Map und ein Array von Bildobjekten:
const COLS = 42;
const ROWS = 42;
const PARENT = foo; // ein bestehendes Element-Objekt
var map = document.createElement("map");
document.body.appendchild(map);
map.name = "myMap";
var area = document.createElement("area");
map.appendchild(area);
area.shape = "poly";
area.coords = "0, 0, 42, 0, 0, 42";
area.onclick = clicked;
var icons = new Array();
for (var col = 0; col < COLS; col++)
{
icons[col] = new Array();
for (var row = 0; row < ROWS; row++)
{
icons[col][row] = new Icon(col, row);
}
}
function Icon(col, row)
{
var icon = document.createElement("img");
icon.col = col;
icon.row = row;
icon.src = "bar";
icon.useMap = "#myMap";
}
function clicked()
{
// ???
}
Im Scope der Funktion 'clicked()' bezieht sich 'this' auf das 'area'-Element, bei dessen 'onclick'-Ereignis die Funktion aufgerufen wird. Wie aber komme ich an die Indizes 'col', 'row' desjenigen Bildes, auf das geclickt wurde?
See ya up the road,
Gunnar
--
„Wer Gründe anhört, kommt in Gefahr nachzugeben.“ (Goethe)
„Wer Gründe anhört, kommt in Gefahr nachzugeben.“ (Goethe)