How do I get position x and y from jQuery ui draggable?

前端 未结 4 2302
灰色年华
灰色年华 2020-12-30 17:04

Here an example http://jsfiddle.net/naqbq/

How do I grab current position for x and y after re-position the image?



        
4条回答
  •  無奈伤痛
    2020-12-30 17:32

    You can obtain the top, and lef:

    $('selector').draggable({
      drag: function(event, ui) {
        ui.position.top; // .left
        // or
        $('selector').position().top; // current position of an element relative to the offset parent
        $('selector').offset(); // retrieves the current position relative to the document. 
      }
    })
    

提交回复
热议问题