pizhu-drag.js 769 B

12345678910111213141516171819202122232425262728
  1. console.info("drag");
  2. //记录被拖拽的元素
  3. var eleDrag = null;
  4. // 为Div添加ondragstart事件
  5. function addDivDragStart() {
  6. $('.item').on('dragstart', function(ev) {
  7. eleDrag = ev.target;
  8. });
  9. }
  10. function dragPreventEvent() {
  11. $(document.body).on('dragover', function(ev) {
  12. ev.preventDefault();
  13. });
  14. $(document.body).on('drop', function(ev) {
  15. ev.preventDefault();
  16. eleDrag.parentNode.removeChild(eleDrag);
  17. // 把光标移到最后
  18. // changeClassName();
  19. });
  20. // 为displayArea添加拖拽事件,用来防止事件冒泡
  21. $('#displayArea').on('dragover', function(ev) {
  22. ev.preventDefault();
  23. });
  24. $('#displayArea').on('drop', function(ev) {
  25. ev.preventDefault();
  26. ev.stopPropagation();
  27. });
  28. }