How to get the distance from the top for an element?

前端 未结 13 1693
北恋
北恋 2020-12-07 12:13

I want to know how to use JavaScript to get the distance of an element from the top of the page not the parent element.

13条回答
  •  挽巷
    挽巷 (楼主)
    2020-12-07 12:41

    Using jQuery's offset() method:

    $(element).offset().top
    

    Example: http://jsfiddle.net/yZGSt/3/

提交回复
热议问题