我试图获取元素的顶部位置和margin-bottom值。
奏效:jQuery添加两个CSS属性值
var top = -$('elem').postion().top; // lets say its -54
var margin = $('elem').css('margin-top'); // lets say its 0
芽我需要添加这些为我的动画功能。所以top+margin
,但jQuery给出-540像素,但它需要返回-54像素..或者当它的负面它只是给-54-10px当我需要-64像素。
有没有办法解决这个问题?我无法想出它,它让我很烦恼!
我的代码:
var top = -$('#id1').position().top;
var margin = $('.scrollable').css('margin-top');
var combine = top+margin;
$('.animate').animate({'margin-top' : combine});
第二个是一个字符串(例如:“10px的”)... – 2012-01-16 15:20:44