Hallo ihr lieben,
Ich arbeite seit einiger zeit einer Seite wo ich nun an einem Punkt angelangt bin wo ich seit mehreren Tagen nicht mehr weiter kommen.
Undzwar will ich das wen man auf ein imag mehrfach klicken kann und dann diese Koordinaten in ein array gespeichert werden.
dh
1 click
X['1'] = coords
Y['1'] = coords
2 click
X['2'] = coords2
Y['2'] = coords2
usw
Da ich eine kompletter javascript noob bin und ich mich nur mit html,css und php auskenne sind die resultate schlecht und ich muss auch sagen ich habe viel viel gegoogelt.
und habe nun ein script gefunden von: vishalsays.wordpress.com
wo ich schoneinmal eine normale Variable habe.
so nun habe ich mit hilfe vom Debbuger und von meinem php wissen versucht etwas dran rum zu schrauben leider ohne Erfolg.
vielleicht könnt ihr mir helfen wie ich es anstelle das wen ich klicke die coords in ein Array gespeichert werden und beim nächsten das array grade um eins vergrößert wird ich bin am verzweifeln.
vielleicht denk ansätze wie zb das und das diese Funktion in die Zeile oder ich weis echt net wie ich da anfangen soll das weiter zu bekommen.
hier mal das script.
Ich arbeite seit einiger zeit einer Seite wo ich nun an einem Punkt angelangt bin wo ich seit mehreren Tagen nicht mehr weiter kommen.
Undzwar will ich das wen man auf ein imag mehrfach klicken kann und dann diese Koordinaten in ein array gespeichert werden.
dh
1 click
X['1'] = coords
Y['1'] = coords
2 click
X['2'] = coords2
Y['2'] = coords2
usw
Da ich eine kompletter javascript noob bin und ich mich nur mit html,css und php auskenne sind die resultate schlecht und ich muss auch sagen ich habe viel viel gegoogelt.
und habe nun ein script gefunden von: vishalsays.wordpress.com
wo ich schoneinmal eine normale Variable habe.
so nun habe ich mit hilfe vom Debbuger und von meinem php wissen versucht etwas dran rum zu schrauben leider ohne Erfolg.
vielleicht könnt ihr mir helfen wie ich es anstelle das wen ich klicke die coords in ein Array gespeichert werden und beim nächsten das array grade um eins vergrößert wird ich bin am verzweifeln.
vielleicht denk ansätze wie zb das und das diese Funktion in die Zeile oder ich weis echt net wie ich da anfangen soll das weiter zu bekommen.
hier mal das script.
Code:
<div id="divid" style="width:250px; height:100px; background:#0809fe;"></div> <br/><br/> Click to add the coordinates in this text field.<br/> <input type="text" name="regcoords" id="regcoords" /> <div id="coords">Coords</div> <script type="text/javascript"><!-- /* Here add the ID of the HTML elements for which to show the mouse coords Within quotes, separated by comma. E.g.: ['imgid', 'divid']; */ var elmids = ['divid']; var x, y = 0; // variables that will contain the coordinates // Get X and Y position of the elm (from: vishalsays.wordpress.com) function getXYpos(elm) { x = elm.offsetLeft; // set x to elm’s offsetLeft y = elm.offsetTop; // set y to elm’s offsetTop elm = elm.offsetParent; // set elm to its offsetParent //use while loop to check if elm is null // if not then add current elm’s offsetLeft to x //offsetTop to y and set elm to its offsetParent while(elm != null) { x = parseInt(x) + parseInt(elm.offsetLeft); y = parseInt(y) + parseInt(elm.offsetTop); elm = elm.offsetParent; } // returns an object with "xp" (Left), "=yp" (Top) position return {'xp':x, 'yp':y}; } // Get X, Y coords, and displays Mouse coordinates function getCoords(e) { // coursesweb.net/ var xy_pos = getXYpos(this); var click = 0; click = click++; // if IE if(navigator.appVersion.indexOf("MSIE") != -1) { // in IE scrolling page affects mouse coordinates into an element // This gets the page element that will be used to add scrolling value to correct mouse coords var standardBody = (document.compatMode == 'CSS1Compat') ? document.documentElement : document.body; x = event.clientX + standardBody.scrollLeft; y = event.clientY + standardBody.scrollTop; } else { x = e.pageX; y = e.pageY; } x = x - xy_pos['xp']; y = y - xy_pos['yp']; // displays x and y coords in the #coords element document.getElementById('coords').innerHTML = 'X= '+ x+ ' ,Y= ' +y; } // register onmousemove, and onclick the each element with ID stored in elmids for(var i=0; i<elmids.length; i++) { if(document.getElementById(elmids[i])) { // calls the getCoords() function when mousemove document.getElementById(elmids[i]).onmousemove = getCoords; // execute a function when click document.getElementById(elmids[i]).onclick = function() { document.getElementById('regcoords').value = x+ ' , ' +y; }; } } --></script>
Kommentar