簡體   English   中英

jQuery在Chrome中點擊可拖動跳轉

[英]Jquery draggable jumps on click in Chrome

我對jQuery Draggable有問題。 我在具有背景圖像的div中有兩個圖像。 我可以在Firefox中單擊並拖動“確定”,但在Chrome中它們都跳到div的左上方。 如果再次單擊並拖動,則可以正常進行。

<!doctype html>
<html>
<head>
<title>Untitled Document</title>
<script src="js/jquery-1.11.1.min.js"></script>
<script src="js/jquery-ui.min.js"></script>
<script src="//code.jquery.com/ui/1.11.3/jquery-ui.js"></script>
<script src="js/jquery.ui.touch-punch.min.js"></script>
<link href="css/styles-test.css" rel="stylesheet" type="text/css">
</head>
<body>
<div class="plot_graph"> <img src="http://petentest.co.uk/images/plotgraph-v3.png" width="100%">
  <div class="drag_container"> <i style="left:51.32211538461539%;top:40.056022408963585%; color: #00C; cursor: move;"  class="pennant-blue fa-5x draggable"> <img src="http://petentest.co.uk/images/pp-blue-pennant-2x.png" width="32" /></i> <i style="left:51.32211538461539%;top:40.056022408963585%; color:#00FFFF; cursor: move;" class="pennant-red fa-5x draggable-manager" > <img src="http://petentest.co.uk/images/pp-red-pennant-2x.png" width="32" /> </i> </div>
</div>
<script>
    $( ".draggable" ).draggable({
    containment: ".drag_container",
    stop: function() {
    var plotX = $(this).position().left / $(this).parent().width() * 100;
    var plotY = $(this).position().top / $(this).parent().height() * 100;
    $('.plot_x').val(plotX);
    $('.plot_y').val(plotY);
    var java_id = $("input[name=java_id]").val();
    //var ajaxurl = 'http://petentest.co.uk/includes/send_user_plot_data.php',
    data =  {
    'performance_plan_id' : java_id,
    'user_plot_x': plotX,
    'user_plot_y': plotY };
    $.post(ajaxurl, data, function (response) {
    console.log("Plot saved successfully.");
    alert('Your position was saved successfully.');
    });
    }
    });
</script> 
<script>
$( ".draggable-manager").draggable({
    containment: ".drag_container",
    stop: function() {
        var plotX = $(this).position().left / $(this).parent().width() * 100;
        var plotY = $(this).position().top / $(this).parent().height() * 100;
    $('.plot_x').val(plotX);
    $('.plot_y').val(plotY);
    var java_id = $("input[name=java_id]").val();
    var ajaxurl = 'http://petentest.co.uk/includes/send_manager_plot_data.php',
    data =  {
    'performance_plan_id' : java_id,
    'manager_plot_x': plotX,
    'manager_plot_y': plotY };

            $.post(ajaxurl, data, function (response) {
        console.log("Plot saved successfully.");
        alert('You cannnot move your manager\'s assessment.');
        });

    }
    });
    </script>
</body>
</html>

JSFiddle: https ://jsfiddle.net/petenaylor/sk75rpuh/

我可以通過在您的三角旗藍色圖標的樣式中添加“ position:absolute”來使其工作。

.pennant-blue {
     position: absolute;
}

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM