0

i have this code https://jsfiddle.net/j8kLz6wm/1/

when i add another image it does not work

 <img ondragstart="return false" id="drag-img" src="http://www.patsoy.com/p/2015/09/geometric-patterns-f03phtdx.jpg" />

and it nicely does what i need,

but i cannot get my head around how to have multiple images in this div which all can be moved freely.

i want to be able to make collages with multiple images.

thanks for any help

1 Answers1

0

I've just gone with your codebase. I think the image url is wrong. it working well with this url https://via.placeholder.com/150. I think you have to check your image url.

You can use classname instead of id to handle this issue.

    <div id="container">
      <img ondragstart="return false" class="drag-img" src="http://www.patsoy.com/p/2015/09/geometric-patterns-f03phtdx.jpg" />
      <img ondragstart="return false" class="drag-img" src="http://www.patsoy.com/p/2015/09/geometric-patterns-f03phtdx.jpg" />
    </div>

And add addEventListener to each items

  var items = document.getElementsByClassName('drag-img');
  for (let item of items) {
    item.addEventListener(event_start, start_drag);
  }

here is the codebase. https://jsfiddle.net/jsdev778/5myvsxzw/21

Hope this help you.

webdev778
  • 51
  • 1
  • 8