在IE7中拖放不起作用

时间:2015-08-19 10:56:58

标签: javascript html5 internet-explorer internet-explorer-7 native

我使用Native HTML5拖放实现了拖放。 它在IE11中工作正常。它也适用于chrome和Firefox。 但在IE7中失败了。我无法找到问题所在。 这有什么解决方案???

这是我的代码:

<html>
<head>
<style>
[draggable] {
  -moz-user-select: none;
  -khtml-user-select: none;
  -webkit-user-select: none;
  user-select: none;
}
.box {
  height: 125px;
  width: 125px;
  float: left;
  border: 3px solid #0092BF;
  background-color: #FFEBDD;
  margin-right: 10px;
  -webkit-border-radius: 10px;
  -moz-border-radius: 10px;
  border-radius: 10px;
  text-align: center;
}
img:hover { cursor:move}
</style>

<body>
<div id="boxes-example">
    <div class="box" draggable="true">
    <img src="drag icon.png" draggable="false" width="16" height="16"/>
        <header>A</header>
        <p>
        order!
        </p>
    </div>

    <div class="box" draggable="true">
    <img src="drag icon.png" width="16" height="16"/>
        <header>B</header>
        <p>
        Put me
        </p>
    </div>
    <div class="box" draggable="true">
    <img src="drag icon.png" width="16" height="16"/>
        <header>C</header>
        <p>
        right
        </p>
    </div>
    <div class="box" draggable="true">
    <img src="drag icon.png" width="16" height="16"/>
        <header>D</header>
        <p>
        into
        </p>
    </div>
    <div class="box" draggable="true">
    <img src="drag icon.png" width="16" height="16"/>
        <header>E</header>
        <p>
        the
        </p>
    </div>
</div>



 <script>
    (function () {
        var id_ = 'boxes-example';
        var boxes_ = document.querySelectorAll('#' + id_ + ' .box');
        var dragSrcEl_ = null;

        this.handleDragStart = function (e) {
            e.dataTransfer.effectAllowed = 'move';
            e.dataTransfer.setData('text/html', this.innerHTML);

            dragSrcEl_ = this;

            this.style.opacity = '0.5';

            // this/e.target is the source node.
            this.addClassName('moving');
        };

        this.handleDragOver = function (e) {
            if (e.preventDefault) {
                e.preventDefault(); // Allows us to drop.
            }

            e.dataTransfer.dropEffect = 'move';

            return false;
        };

        this.handleDragEnter = function (e) {
            this.addClassName('over');
        };

        this.handleDragLeave = function (e) {
            // this/e.target is previous target element.

            this.removeClassName('over');
        };

        this.handleDrop = function (e) {
            // this/e.target is current target element.

            if (e.stopPropagation) {
                e.stopPropagation(); // stops the browser from redirecting.
            }

            // Don't do anything if we're dropping on the same box we're dragging.
            if (dragSrcEl_ != this) {
                dragSrcEl_.innerHTML = this.innerHTML;
                this.innerHTML = e.dataTransfer.getData('text/html');
            }

            return false;
        };

        this.handleDragEnd = function (e) {
            // this/e.target is the source node.
            this.style.opacity = '1';

            [ ].forEach.call(boxes_, function (box) {
                box.removeClassName('over');
                box.removeClassName('moving');
            });
        };

        [ ].forEach.call(boxes_, function (box) {
            box.setAttribute('draggable', 'true');  // Enable boxes to be draggable.
            box.addEventListener('dragstart', this.handleDragStart, false);
            box.addEventListener('dragenter', this.handleDragEnter, false);
            box.addEventListener('dragover', this.handleDragOver, false);
            box.addEventListener('dragleave', this.handleDragLeave, false);
            box.addEventListener('drop', this.handleDrop, false);
            box.addEventListener('dragend', this.handleDragEnd, false);
        });
    })();
</script>

0 个答案:

没有答案