adding pixels to jquery .css() left property

后端 未结 6 1255

This is my code:

var lef=$(this).css(\"left\");
var top=$(this).css(\"top\");
alert(lef);
$(this).after(\"
6条回答
  •  天涯浪人
    2020-12-09 15:34

    I've simplified thirtydot answer. You can use this jQuery function for any property you want to add pixels.

    jQuery.fn.addPixelsTo = function(property, pxls) {    
         return $(this[0]).css(property, (parseInt($(this[0]).css(property).substr(0,2))+pxls)+'px');
    }
    

    Example:

    $('#element').addPixelsTo('border-top-width', 30);
    

提交回复
热议问题