Padding or margin value in pixels as integer using jQuery

后端 未结 14 2183
陌清茗
陌清茗 2020-11-28 02:40

jQuery has height() en width() functions that returns the height or width in pixels as integer...

How can I get a padding or margin value of an element in p

14条回答
  •  挽巷
    挽巷 (楼主)
    2020-11-28 03:24

    Shamelessly adopted from Quickredfox.

    jQuersy.fn.cssNum = function(){
        return parseInt(jQuery.fn.css.apply(this, arguments), 10);
    };
    

    update

    Changed to parseInt(val, 10) since it is faster than parseFloat.

    http://jsperf.com/number-vs-plus-vs-toint-vs-tofloat/20

提交回复
热议问题