拖动n Drop在缩放容器时无法正常工作 [英] Drag n Drop not working proper on scaling the container

查看:61
本文介绍了拖动n Drop在缩放容器时无法正常工作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我将容器缩放到0.5时,DND无法正常工作. 请任何人帮我解决问题.

When I zoom the container to 0.5 then the DND does not behave properly. Please anyone help me solve the issue.

HTML:

<div id="container">
<div id="dragContainer">
<div class="draggable">drag1</div>
<div class="draggable">drag2</div>
</div>
<div id="dropContainer">
<div class="droppable">drop1</div>
<div class="droppable">drop2</div>
</div>
</div>

JS:

$(".draggable").draggable({
    revert: 'invalid'
})
$(".droppable").droppable()

我创建了该问题的小提琴链接: https://jsfiddle.net/7eqnhsp3/

I have created fiddle link of the issue: https://jsfiddle.net/7eqnhsp3/

推荐答案

我已经创建了可以在任意缩放情况下运行的演示

I have created demo which runs in any case of Scaling

    <html>
    <head>
    <style>
    #container{
      width:500px;
      height:500px;
      position:absolute;
      top:0px;
      left:0px;
      border:1px solid;
      -ms-transform: scale(0.8,0.8); /* IE 9 */
      -webkit-transform: scale(0.8,0.8); /* Safari */
       transform: scale(1,1);

    }
    #dragContainer,#dropContainer{
     width:200px;
      height:500px;
      position:relative;
      margin-top:0px;
      margin-left:0px;
      border:1px solid gray;
      float:left;
    }
    .draggable{
      width:50px;
      height:30px;
      background:#990000;
      border:1px solid;
      z-index:1;
    }
    .droppable{
      width:50px;
      height:30px;
      background:#aa0000;
      border:1px solid;
    }
    </style>
    <script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.0.0-beta1/jquery.js"></script>
    <script src="https://cdnjs.cloudflare.com/ajax/libs/jqueryui/1.11.4/jquery-ui.js"></script>
    <script>
    var zoomScale=1;
        $(document).ready(function(){

                $(".draggable").draggable({
                revert: 'invalid'
                })
                $(".draggable").draggable({
                    //start: startFix,
                    drag: dragFix
                });
                $(".droppable").droppable()

        })


            function dragFix(event, ui) {
                var changeLeft = ui.position.left - ui.originalPosition.left; // find change in left
                var newLeft = ui.originalPosition.left + changeLeft / zoomScale; // adjust new left by our zoomScale

                var changeTop = ui.position.top - ui.originalPosition.top; // find change in top
                var newTop = ui.originalPosition.top + changeTop / zoomScale; // adjust new top by our zoomScale

                ui.position.left = newLeft;
                ui.position.top = newTop;

            }
    </script>
    </head>
    <body>


    <div id="container">
    <div id="dragContainer">
    <div class="draggable">drag1</div>
    <div class="draggable">drag2</div>
    </div>
    <div id="dropContainer">
    <div class="droppable">drop1</div>
    <div class="droppable">drop2</div>
    </div>
    </div>
    </body>
    </html>

这篇关于拖动n Drop在缩放容器时无法正常工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆