Convert absolute position to relative

前端 未结 5 1244
一生所求
一生所求 2021-01-19 00:52

Is it possible to change DIV position from absolute to relative (and from relative to absolute)? DIV should remain on same place.

5条回答
  •  陌清茗
    陌清茗 (楼主)
    2021-01-19 01:50

    prototype.js has element.absolutize() and element.relativize which work very well.

    The problem with going from relative to absolute is that element.offsetTop and offsetLeft

    only give the offset of your element to its parent. You need to measure the cumualtive offset (i.e.

    the offset of your element to its parent +
    the offset of the parent to its parent +
    the offset of its parent to its parent +
    

    etc.)

提交回复
热议问题