Get and set position with jQuery .offset()

后端 未结 5 772
长发绾君心
长发绾君心 2020-12-07 14:06

How to get and set the position of an element with the jQuery .offset method?

Let\'s say I have a div layer1 and another layer2

5条回答
  •  遥遥无期
    2020-12-07 14:10

    It's doable but you have to know that using offset() sets the position of the element relative to the document:

    $('.layer1').offset( $('.layer2').offset() );
    

提交回复
热议问题