拖放滚动

时间:2018-08-03 18:54:44

标签: javascript html scroll drag-and-drop drag

我想进行拖放,但是当内容可滚动时,如果它不在拖动区域的边缘,则不会移动;如果内容不在边缘,则不会移动。

有css或javascript属性可以在可滚动区域之外滚动吗?

Image error

function allowDrop(ev) {
    ev.preventDefault();
}

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

function drop(ev) {
  ev.preventDefault();
}
#contenedor {
  height: 500px;
  width: 4000px; 
  background: rgba(48,105,248,1);
  background: -moz-linear-gradient(left, rgba(48,105,248,1) 0%, rgba(240,91,151,1) 20%, rgba(115,230,39,1) 46%, rgba(255,67,46,1) 80%, rgba(39,106,231,1) 100%);
  background: -webkit-gradient(left top, right top, color-stop(0%, rgba(48,105,248,1)), color-stop(20%, rgba(240,91,151,1)), color-stop(46%, rgba(115,230,39,1)), color-stop(80%, rgba(255,67,46,1)), color-stop(100%, rgba(39,106,231,1)));
  background: -webkit-linear-gradient(left, rgba(48,105,248,1) 0%, rgba(240,91,151,1) 20%, rgba(115,230,39,1) 46%, rgba(255,67,46,1) 80%, rgba(39,106,231,1) 100%);
  background: -o-linear-gradient(left, rgba(48,105,248,1) 0%, rgba(240,91,151,1) 20%, rgba(115,230,39,1) 46%, rgba(255,67,46,1) 80%, rgba(39,106,231,1) 100%);
  background: -ms-linear-gradient(left, rgba(48,105,248,1) 0%, rgba(240,91,151,1) 20%, rgba(115,230,39,1) 46%, rgba(255,67,46,1) 80%, rgba(39,106,231,1) 100%);
  background: linear-gradient(to right, rgba(48,105,248,1) 0%, rgba(240,91,151,1) 20%, rgba(115,230,39,1) 46%, rgba(255,67,46,1) 80%, rgba(39,106,231,1) 100%);
  filter: progid:DXImageTransform.Microsoft.gradient( startColorstr='#3069f8', endColorstr='#276ae7', GradientType=1 );

}

#main {
  position:relative;
  overflow: auto;
  height: 400px !important;
  margin: 0;
  margin: 100px;
}

body{
  margin: 0;
  padding: 0;
}

#cubo {
  height: 200px;
  width: 200px;
  background: green;
  position: absolute;
  left: 0;
  top: 0;
}
<div id="main"  >
  <div id="contenedor" ondrop="drop(event)" ondragover="allowDrop(event)" >
    <div id="cubo" draggable="true" ondragstart="drag(event)" ></div>
  </div>
</div>

0 个答案:

没有答案
相关问题