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

前端 未结 7 1019
感情败类
感情败类 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:05

    Use offset() function of jQuery. Here it would be:

    $container.offset({
            'left': 100,
            'top': mouse.y - ( event_state.mouse_y - event_state.container_top ) 
        });
    

提交回复
热议问题