拖动无法在Internet Explorer中工作

时间:2015-02-05 06:54:03

标签: javascript jquery html css internet-explorer

我试图调整大小以及在我的code.code中拖动div。下面,但是我根本无法拖动div,但我可以在chrome中执行相同操作。但是调整大小在两者中都有效。请检查并指导我如何在拖拽工作中使用ie。

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>

1 个答案:

答案 0 :(得分:1)

IE8不支持transform,因此您的onmove处理程序无法在此处运行。此外,IE8不支持textContent,因此您的onend处理程序也无效。

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