jQuery How to Get Element's Margin and Padding?

前端 未结 8 2224
感动是毒
感动是毒 2020-12-02 09:20

Just wondering - how using jQuery - I can get an elements formatted total padding and margin etc ? i.e. 30px 30px 30px 30px or 30px 5px 15px 30px etc

I tried

<
8条回答
  •  囚心锁ツ
    2020-12-02 09:41

    $('img').margin() or $('img').padding()
    

    return:

    {bottom: 10 ,left: 4 ,top: 0 ,right: 5}
    

    get value:

    $('img').margin().top
    

    Edit:

    use jquery plugin: jquery.sizes.js

提交回复
热议问题