<tfoot id='VRpDo'></tfoot>
  • <legend id='VRpDo'><style id='VRpDo'><dir id='VRpDo'><q id='VRpDo'></q></dir></style></legend>
    <i id='VRpDo'><tr id='VRpDo'><dt id='VRpDo'><q id='VRpDo'><span id='VRpDo'><b id='VRpDo'><form id='VRpDo'><ins id='VRpDo'></ins><ul id='VRpDo'></ul><sub id='VRpDo'></sub></form><legend id='VRpDo'></legend><bdo id='VRpDo'><pre id='VRpDo'><center id='VRpDo'></center></pre></bdo></b><th id='VRpDo'></th></span></q></dt></tr></i><div id='VRpDo'><tfoot id='VRpDo'></tfoot><dl id='VRpDo'><fieldset id='VRpDo'></fieldset></dl></div>

    <small id='VRpDo'></small><noframes id='VRpDo'>

        <bdo id='VRpDo'></bdo><ul id='VRpDo'></ul>
      1. HTML5 Draggable setDragImage 不适用于 Chrome 上的画布

        时间:2023-06-20

        <small id='RR2Ie'></small><noframes id='RR2Ie'>

          <bdo id='RR2Ie'></bdo><ul id='RR2Ie'></ul>

            • <i id='RR2Ie'><tr id='RR2Ie'><dt id='RR2Ie'><q id='RR2Ie'><span id='RR2Ie'><b id='RR2Ie'><form id='RR2Ie'><ins id='RR2Ie'></ins><ul id='RR2Ie'></ul><sub id='RR2Ie'></sub></form><legend id='RR2Ie'></legend><bdo id='RR2Ie'><pre id='RR2Ie'><center id='RR2Ie'></center></pre></bdo></b><th id='RR2Ie'></th></span></q></dt></tr></i><div id='RR2Ie'><tfoot id='RR2Ie'></tfoot><dl id='RR2Ie'><fieldset id='RR2Ie'></fieldset></dl></div>
            • <legend id='RR2Ie'><style id='RR2Ie'><dir id='RR2Ie'><q id='RR2Ie'></q></dir></style></legend>

              <tfoot id='RR2Ie'></tfoot>
                <tbody id='RR2Ie'></tbody>

                  本文介绍了HTML5 Draggable setDragImage 不适用于 Chrome 上的画布的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  我正在尝试在原生 HTML5 Drag And Drop API 中使用画布作为我的拖动图像.

                  I'm trying to use canvas as my drag image in native HTML5 Drag And Drop API.

                  问题是它可以在 Firefox 上运行,但不能在 Chrome (58) 上运行,我无法确定问题所在.

                  The problem is that it works on Firefox but not on Chrome (58) and I can't pinpoint the problem.

                  代码:https://jsfiddle.net/196urLwd/5/

                  <div id="thing" draggable="true">DRAG ME</div>
                  

                  <小时>

                  function onDragStart(event){
                  
                      var canvas = document.createElement('canvas');
                      var context = canvas.getContext('2d');
                  
                      canvas.width = 100;
                      canvas.height = 20;
                  
                      context.fillStyle = '#333333';
                      context.fillRect(0, 0, canvas.width, canvas.height);
                  
                      context.fillStyle = '#999999';
                      context.font = 'bold 13px Arial';
                      context.fillText('DRAGGING...', 5, 15);
                  
                      event.dataTransfer.setData('text', 'lorem ipsum');
                      event.dataTransfer.effectAllowed = 'copy';    
                      event.dataTransfer.setDragImage(canvas, -15, 9);
                  
                  };
                  
                  var theThing = document.getElementById('thing');
                  theThing.addEventListener('dragstart', onDragStart, false);
                  

                  我做错了什么?

                  推荐答案

                  Chrome好像要求canvas在dom中

                  Chrome seems to require the canvas to be in the dom

                  document.body.append(canvas);
                  

                  然后用一些 css 隐藏它

                  and just hide it with some css

                  canvas{
                    position:absolute;
                    left:-100%;
                  }
                  

                  https://jsfiddle.net/196urLwd/6/

                  这篇关于HTML5 Draggable setDragImage 不适用于 Chrome 上的画布的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  上一篇:读取画布像素的 RGB 值 下一篇:将修改后的 SVG 绘制到画布上

                  相关文章

                      • <bdo id='NHe5r'></bdo><ul id='NHe5r'></ul>
                      <legend id='NHe5r'><style id='NHe5r'><dir id='NHe5r'><q id='NHe5r'></q></dir></style></legend>

                      <small id='NHe5r'></small><noframes id='NHe5r'>

                    1. <i id='NHe5r'><tr id='NHe5r'><dt id='NHe5r'><q id='NHe5r'><span id='NHe5r'><b id='NHe5r'><form id='NHe5r'><ins id='NHe5r'></ins><ul id='NHe5r'></ul><sub id='NHe5r'></sub></form><legend id='NHe5r'></legend><bdo id='NHe5r'><pre id='NHe5r'><center id='NHe5r'></center></pre></bdo></b><th id='NHe5r'></th></span></q></dt></tr></i><div id='NHe5r'><tfoot id='NHe5r'></tfoot><dl id='NHe5r'><fieldset id='NHe5r'></fieldset></dl></div>
                      <tfoot id='NHe5r'></tfoot>