Monday, 15 September 2014

position - jquery inconsistent positioning using offset().top -



position - jquery inconsistent positioning using offset().top -

i trying position #elementa relative #elementb. half time ends 1 top value, half time gets another, , can't figure out why. #elementa begins css:

#elementa { display: block; opacity: 0; position: absolute; clear: both; margin-left: -49px; }

then, on $(document).ready(), set top value , fade in.

var p = $('#elementb').offset(); $('#elementa').css({ top: p.top - 2 }); $('#elementa').animate({opacity: 1}, 400);

why getting inconsistent results? there improve way this?

i found problem. thought because executing on $(document).ready() wouldn't have worry assets loading affecting positioning. turned out image above #elementa throwing off when didn't load in time. waiting $('other image').load() fixes it.

jquery position positioning offset

No comments:

Post a Comment