sarpay
11/30/2014 - 6:49 PM

[jquery] [css] Dynamically position an object relative to another

[jquery] [css] Dynamically position an object relative to another

//*** position object "that" 4px below object "this".

var thisTopPosition, thisHeight, thisBottomPosition, thatTopPosition;
thisTopPosition = $('#resultitem').offset().top; //*** use ".position().top" as alternative
thisHeight = $('#resultitem').height();
thisBottomPosition = thisTopPosition + thisHeight;
thatTopPosition = thisBottomPosition + 4;
$('<style>#ui-tooltip { top: ' + thatTopPosition + 'px; }</style>').appendTo('head');

//*** use the following code to perform scroll animation to position
$('html, body').animate({scrollTop: thatTopPosition }, 300);