简体   繁体   中英

How to detect margin-left of element with jQuery

Wird, I thought this is obvious but not necessarily, can anybody tell me how to detect margin with jQuery? I have this and in console i have good result but it's not working on page:

var margin_left = circle.css('margin-left').toLowerCase();
circles_container.css('margin-left', -margin_left + 'px');

Much thx for help.

I would say this should be more accurate:

var margin_left = circle.css('margin-left');
circles_container.css({marginLeft: '-'+margin_left});

OK i have this and also it's work:

var margin_left = l_circle.css('margin-left').replace("px", "");
container.css('margin-left', -margin_left + 'px');

Try this -

var marginLeftVal = circle.css('marginLeft');
marginLeftVal = parseInt(marginLeftVal)*-1;
circles_container.css({
            marginLeft: marginLeftVal 
});

YOu could also start using the JSizes library.

Found on this page: http://www.bramstein.com/projects/jsizes/

Allows you to easily retrieve or set a property of margin, padding, or other attributes.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM