Drag-n-Drop on contentEditable elements

前端 未结 3 1131
星月不相逢
星月不相逢 2020-12-15 08:38

There are numerous WYSIWYG editors available on the internet, but I\'m yet to find one that implements some form of drag-n-drop implementation.

It is easy to create

3条回答
  •  囚心锁ツ
    2020-12-15 09:32

    If I understand what you're saying, then this is just basic drag and drop. The solution below should be close to the best answer for FIREFOX. I'm sure there are different functions for IE. Go to http://www.html5rocks.com/en/tutorials/dnd/basics/ for more help.

    Set the "draggable" attribute of the object you want to drag, and set the object's "ondragstart" method to "dragStartHandler" or whatever your function is called.

    // You can set this to 'text/plain' if you don't want to insert HTML content
    var internalDNDType = 'text/html';
    
    function dragStartHandler(event) {
      // This is whatever html data you want to insert.
      var textContent = ""+userFirstName+"";
    
      event.dataTransfer.setData(internalDNDType, textContent);
      event.dataTransfer.effectAllowed = 'copy';
    }
    
    function dragEnterHandler(event)
    {
      event.preventDefault();
      return false;
    }
    
    function dragOverHandler(event)
    {
      event.preventDefault();
      return false;
    }
    
    function dropHandler(event) {
      event.preventDefault();
      event.stopPropogation();
      return false;
    }
    

提交回复
热议问题