In jQuery how can I set “top,left” properties of an element with position values relative to the parent and not the document?

前端 未结 7 1039
感情败类
感情败类 2020-12-12 18:43

.offset([coordinates]) method set the coordinates of an element but only relative to the document. Then how can I set coordinates of an element but relative to

7条回答
  •  孤城傲影
    2020-12-12 19:11

    You could try jQuery UI's .position method.

    $("#mydiv").position({
      of: $('#mydiv').parent(),
      my: 'left+200 top+200',
      at: 'left top'
    });
    

    Check the working demo.

提交回复
热议问题