user3879222 user3879222 - 5 months ago 24
jQuery Question

Margin top calculations in animate jquery

I need to subtract

10%
from the window
height/2
but with no result , what is the problem ?

var loadingMargin = $(window).height()/2;
$(".loading .sk-circle").animate({
marginTop: loadingMargin-10+"%"
});

Answer

Calculate 90percentage and set value

var loadingMargin = ($(window).height() / 2) * .9;
$(".loading .sk-circle").animate({
  marginTop: loadingMargin
});