jquery css位置offset()

來源:互聯網
上載者:User

傳回值:Object{top,left}

offset()概述

擷取匹配元素在當前視口的相對位移。

返回的對象包含兩個整型屬性:top 和 left。此方法只對可見元素有效。

樣本描述:

擷取第二段的位移

HTML 程式碼:<p>Hello</p><p>2nd Paragraph</p>

jQuery 代碼:var p = $("p:last"); var offset = p.offset(); p.html( "left: " + offset.left + ", top: " + offset.top );

結果:<p>Hello</p><p>left: 0, top: 35</p>

相關文章

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.