ds000001 2014-09-25 15:54
浏览 18

显示每个可拖动元素的位置

Ok, so heres some of my code on js fiddle at . The current code allows me to move the objects and it shows the stop and starting position of the object relative to its constraint. What I am needing to do, is to get the position returned of EACH object. I need them stored in separate vars. The idea is they will be able to add new shapes dynamically and those shapes will all return there coordinates and I can allow them to "SAVE" which will use all those variables and AJAX them to a database. Currently it only returns the latest dragged object, how can I modify this to allow it to show each objects position. I'm a little new to playing with JQuery/JQueryUI so any push in the right direction is helpful.

http://jsfiddle.net/ryv8kz9g/

    $( init );
function init() {
  $('.square, .round').draggable({
    containment: '#layout-area',  start: function(event, ui) {

        // Show start dragged position of image.
        var Startpos = $(this).position();
        $("div#start").text("START: 
X: "+ Startpos.left + "
Y: " + Startpos.top);
    },

    // Find position where image is dropped.
    stop: function(event, ui) {

        // Show dropped position.
        var Stoppos = $(this).position();
        $("div#stop").text("CURRENT: 
X: "+ Stoppos.left + "
Y: " + Stoppos.top);
    }

});
}
    $(document).ready(function() {
        var params = {
            // Callback fired on rotation start.
            start: function(event, ui) {
            },
            // Callback fired during rotation.
            rotate: function(event, ui) {
            },
            // Callback fired on rotation end.
            stop: function(event, ui) {
            },
        };
        $('#table, #table1, #table2, #table3, #table4, #table5').rotatable(params);

    });

Thanks!

  • 写回答

1条回答 默认 最新

  • dqqvravff05370501 2014-09-25 16:35
    关注

    you can use drag:function(event, ui), i have created one in my jsfiddle, check this out.

    http://jsfiddle.net/Arindamnayak/bcxex133/

    <div id="layout-area">
    
      <div id="table" class="square resize"> </div>
    <div id="table2" class="square resize"> </div>
    <div id="table3" class="round resize"> </div>
    <div id="table4" class="round resize"> </div>
    <div id="table5" class="square resize"> </div>
      <div id="table" class="square resize"> </div>
    <div id="table2" class="square resize"> </div>
    <div id="table3" class="round resize"> </div>
    <div id="table4" class="round resize"> </div>
    <div id="table5" class="square resize"> </div>
    </div>
    <div id="start">Waiting for dragging the image get started...</div>
        <div id="start">Waiting for dragging the image get started...</div>
    <div id="current">Waiting image getting dropped...</div>
    
    $( init );
    function init() {
      $('.square, .round').draggable({
        containment: '#layout-area',  start: function(event, ui) {
    
            // Show start dragged position of image.
            var Startpos = $(this).position();
            $("div#start").text("START: 
    X: "+ Startpos.left + "
    Y: " + Startpos.top);
        },
          drag: function(event, ui){
              var Startpos = $(this).position();
            $("div#current").text("Current: 
    X: "+ Startpos.left + "
    Y: " + Startpos.top);
          },
        // Find position where image is dropped.
        stop: function(event, ui) {
    
            // Show dropped position.
            var Stoppos = $(this).position();
            $("div#stop").text("CURRENT: 
    X: "+ Stoppos.left + "
    Y: " + Stoppos.top);
        }
    
    });
    }
        $(document).ready(function() {
            var params = {
                // Callback fired on rotation start.
                start: function(event, ui) {
                },
                // Callback fired during rotation.
                rotate: function(event, ui) {
                },
                // Callback fired on rotation end.
                stop: function(event, ui) {
                },
                drag: function(event, ui){
                }
            };
            $('#table, #table1, #table2, #table3, #table4, #table5').rotatable(params);
    
        });
    
    评论

报告相同问题?

悬赏问题

  • ¥15 公交车和无人机协同运输
  • ¥15 stm32代码移植没反应
  • ¥15 matlab基于pde算法图像修复,为什么只能对示例图像有效
  • ¥100 连续两帧图像高速减法
  • ¥15 组策略中的计算机配置策略无法下发
  • ¥15 如何绘制动力学系统的相图
  • ¥15 对接wps接口实现获取元数据
  • ¥20 给自己本科IT专业毕业的妹m找个实习工作
  • ¥15 用友U8:向一个无法连接的网络尝试了一个套接字操作,如何解决?
  • ¥30 我的代码按理说完成了模型的搭建、训练、验证测试等工作(标签-网络|关键词-变化检测)