使用 HTML5 拖放时无法通过鼠标滚轮滚动页面。

6

使用HTML5拖放功能时,似乎无法使用鼠标滚轮滚动页面。我在任何HTML5拖放实时演示中都看到了这个问题的发生。有没有解决这个问题的方法?


1
嗨@Shelef,我遇到了同样的问题。不知道你找到解决方法了吗? - TungPham
3个回答

0

这可能不是唯一的原因,但在我的情况下,有一个带有pointer-events: none的叠加元素阻止了在Chrome中拖动时的滚动。


-1

有一些演示可以进行页面滚动。尝试这段代码:

  <style type = "text/css">
     #boxA, #boxB {
        float:left;padding:10px;margin:10px;-moz-user-select:none;
     }

     #boxA { background-color: #6633FF; width:75px; height:75px;  }
     #boxB { background-color: #FF6699; width:150px; height:150px; }
  </style>

  <script type = "text/javascript">

     function dragStart(ev) {
        ev.dataTransfer.effectAllowed = 'move';
        ev.dataTransfer.setData("Text", ev.target.getAttribute('id'));
        ev.dataTransfer.setDragImage(ev.target,0,0);
        return true;
     }

     function dragEnter(ev) {
        event.preventDefault();
        return true;
     }

     function dragOver(ev) {
        return false;
     }

     function dragDrop(ev) {
        var src = ev.dataTransfer.getData("Text");
        ev.target.appendChild(document.getElementById(src));
        ev.stopPropagation();
        return false;
     }
  </script>

  <center>
     <h2>Drag and drop HTML5 demo</h2>
     <div>Try to move the purple box into the pink box.</div>

     <div id = "boxA" draggable = "true"
        ondragstart = "return dragStart(ev)">
        <p>Drag Me</p>
     </div>

     <div id = "boxB" ondragenter = "return dragEnter(ev)" 
        ondrop = "return dragDrop(ev)" 
        ondragover = "return dragOver(ev)">Dustbin
     </div>
  </center>

调整窗口大小。


有没有运行的示例? - Shelef

-2

这是可用的代码。可以展示工作页面的截图附件。我通过添加一些div来更改源代码,以使页面滚动。 代码来源:https://www.w3schools.com/html/tryit.asp?filename=tryhtml5_draganddrop

<!DOCTYPE HTML>
<html>
<head>
<style>
#div1 {
    width: 350px;
    height: 70px;
    padding: 10px;
    border: 1px solid #aaaaaa;
}

</style>
<script>
    function allowDrop(ev) {
    ev.preventDefault();
    }

    function drag(ev) {
    ev.dataTransfer.setData("text", ev.target.id);
    }

    function drop(ev) {
    ev.preventDefault();
    var data = ev.dataTransfer.getData("text");
    ev.target.appendChild(document.getElementById(data));
    }
</script>
</head>
<body>

    <p>Drag the W3Schools image into the rectangle:</p>

    <div id="div1" ondrop="drop(event)" ondragover="allowDrop(event)"></div>
    <br>

    <img id="drag1" src="images.jpg" alt="image can not be seen"draggable="true"       ondragstart="drag(event)" width="300" height="68">
<div id="middle" style="height:50px;width:1200px;background-color:blue;margin-top:300px;"><p>This is a test div</p> </div>
    <div id="bottom" style="height:50px;width:1200px;background-color:yellow;margin-  top:400px;"><p>This is another test div</p></div>


</body>
</html>

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接