Parking :: CodePen - 2 - Can you park here?

See CSS-tricks: Creating a Parking Game With the HTML Drag and Drop API.

Browser testing on PC under Windows7 for https://codepen.io/yelly/full/NyXYrV/. *)

March 12, 2018

Update March 14, 2018.
- In the meantime Firefox 59.0 is arrived. All behaviors are the same as in FF58.
- Chrome is now vs. 65.0.3325.162, also everything the same.


1. Just dropping all vehicles

Testing

Conclusions

Workaround

Omit the .drop-zone {display:flex}, and give the dropped images a fitting width: .drop-zone img {width: 150px}.


2. Dropping on top of existing dropped vehicle (1)

Testing

Conclusion

Workaround

See next item.


3. Dropping on top of existing dropped vehicle (2)

Testing

Conclusion

Workaround

Deny the existing vehicle(s) in the target box by giving it/them a temporary {display: none} during the onDragEnter, by means of a tmp ID (target.id='newVehicle';) in the javascript, combined with #newVehicle img {display: none;} in the CSS. Then overlapping is impossible. At dropping (onDrop), the tmp ID is removed, and everything is visible again.
For the case you drag a vehicle and are still floating above the drop area (but not dropping), and you decide to move away (onDragLeave), also the tmp ID is removed in order to show the already dropped vehicles.
Pitfall is that dragging a dropped vehicle out of the target box lets it disappear outside. That can be avoided by prohibiting further dragging in the onDrop: by adding dragged.setAttribute('draggable','false');.


Parking :: CodePen - 3 - Can you park here?

4. The final result

Browser testing on PC under Windows7 https://codepen.io/yelly/pen/jZQVBJ. *)

Testing

Conclusions

___________________________________
*) Not tested in MS-Edge, nor on tablets or mobile devices. - Some more browser/OS information on Caniuse.com: https://caniuse.com/#search=drag.