http://jsfiddle.net/p3unbmdy/
Javascript function:
$("#container").bind('scroll', function() {
var fromTop = 50;
var scrollVal = $("#container").scrollTop();
var top = 0;
if ( scrollVal > fromTop) {
top = scrollVal - fromTop;
$('#rightElement').css({'position':'absolute','right':'1em','top' :top+'px'});
} else {
$('#rightElement').css({'position':'static','top':'0px'});
}
});