拖动在InternetExplorer中不起作用

dragging not working in internet explorer

本文关键字:不起作用 InternetExplorer 拖动      更新时间:2023-09-26

我正在尝试调整大小,并在我的代码中拖动一个div。代码如下,但我在ie中根本无法拖动div,但我可以在chrome中拖动。但调整大小对两者都有效。请检查并指导我如何在例如中进行拖动

interact('.divname')
  .resizable(true)
  .on('resizemove', function (event) {
    var target = event.target;
    // add the change in coords to the previous width of the target element
    var
      newWidth  = parseFloat(target.style.width ) + event.dx,
      newHeight = parseFloat(target.style.height) + event.dy;
    // update the element's style
    target.style.width  = newWidth + 'px';
    target.style.height = newHeight + 'px';
    //target.textContent = newWidth + '×' + newHeight;
  });  

interact('.divname')
  .draggable({
    // enable inertial throwing
    inertia: true,
    // keep the element within the area of it's parent
    restrict: {
      restriction: "parent",
      endOnly: true,
      elementRect: { top: 0, left: 0, bottom: 1, right: 1 }
    },
    // call this function on every dragmove event
    onmove: function (event) {
      var target = event.target,
          // keep the dragged position in the data-x/data-y attributes
          x = (parseFloat(target.getAttribute('data-x')) || 0) + event.dx,
          y = (parseFloat(target.getAttribute('data-y')) || 0) + event.dy;
      // translate the element
      target.style.webkitTransform =
      target.style.transform =
        'translate(' + x + 'px, ' + y + 'px)';
      // update the posiion attributes
      target.setAttribute('data-x', x);
      target.setAttribute('data-y', y);
    },
    // call this function on every dragend event
    onend: function (event) {
      var textEl = event.target.querySelector('p');
      textEl && (textEl.textContent =
        'moved a distance of '
        + (Math.sqrt(event.dx * event.dx +
                     event.dy * event.dy)|0) + 'px');
    }
  });

<div class="divname">
</div>

IE8不支持transform,因此您的onmove处理程序将无法在那里工作。此外,IE8中不支持textContent,因此您的onend处理程序将无法正常工作。

对于IE9,您可以进行转换,但需要使用类似于webkit的供应商前缀ms