<div id="test"></div>
<div id="test"></div>
<div id="test"></div>
$(window).on('load resize', function () {
$('#test').each(function () {
var topPosition = $(window).height() - $(this).height();
if (topPosition < 0) {
$(this).css('top', topPosition)
} else {
$(this).css('top', 0)
}
});
});