我試圖獲取元素的頂部位置和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