Note that there are some explanatory texts on larger screens.

plurals
  1. POWhy are my event listeners only working for the last element?
    primarykey
    data
    text
    <p>The problem is that when I drag/drop a picture, it always gets put on the last letter. Here's an image of what I am talking about:</p> <p><img src="https://i.stack.imgur.com/FD8uE.png" alt="enter image description here"></p> <p>Here is my code:</p> <pre><code>function mattes_draw_letter(x, y, width, height, letter, position) { var canvas = document.createElement('canvas'); canvas.style.position = "absolute"; canvas.style.top = 0 + "px"; canvas.id = "canvas_opening_" + position; canvas.style.zIndex = 5; var ctx = canvas.getContext("2d"); ctx.lineWidth = 1; ctx.fillStyle = '#bfbfbf'; ctx.strokeStyle = '#000000'; ctx.beginPath(); ctx.moveTo(x + letter[0] * width, y + letter[1] * height); for (i = 0; i &lt; letter.length; i+=2) { if (typeof letter[i+3] !== 'undefined') { ctx.lineTo(x + letter[i+2] * width, y + letter[i+3] * height); } } ctx.fill(); ctx.stroke(); ctx.closePath(); $("#mattes").append(canvas); canvas.addEventListener("drop", function(event) {drop(event, this);}, false); canvas.addEventListener("dragover", function(event) {allowDrop(event);}, false); canvas.addEventListener("click", function() {photos_add_selected_fid(this);}, false); } </code></pre> <p>Here is the code that has the for loop:</p> <pre><code>function mattes_create_openings(openings) { var opening_array = new Array(); var x = 0; var y = 0; var opening_width = 0; var opening_height = 0; $(openings).each(function(i, el) { x = $(el).find("x").text() * ppi; y = $(el).find("y").text() * ppi; opening_width = $(el).find("width").text() * ppi; opening_height = $(el).find("height").text() * ppi; var type = $(el).find("type").text(); var text = $(el).find("text").text(); var ellipse = (type == "ellipse") ? " border-radius: 50% " : ""; if ("letter" == type) { var letter = mattes_get_letter_array(text); var letter_width = (opening_width - (text.length * 0.5 * ppi)) / text.length; var space = 0.5 * ppi; var letterX = x; var letterY = y; var letter_height = opening_height; mattes_draw_letter(letterX, letterY, letter_width, letter_height, letter, i); letterX += (space + letter_width); } else { $("#mattes").append("&lt;div id='opening_" + i + "' style='background-color: #bfbfbf; position: absolute; left: " + x + "px; top: " + y + "px; height: " + opening_height + "px; width: " + opening_width + "px; overflow: hidden; z-index: 4;" + ellipse + "' ondrop='drop(event, this)' ondragover='allowDrop(event)' onclick='photos_add_selected_fid(this);'&gt;&amp;nbsp;&lt;/div&gt;"); } //TODO multiple openings max/min -x,y,width, height opening_array["x"] = x; opening_array["y"] = y; opening_array["opening_width"] = opening_width; opening_array["opening_height"] = opening_height; }); return opening_array; } </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload