function setResultText() {
var winScroll = $(window).scrollTop(),
topMargin = 101,
$resultBlock = $('.result'),
$elements = $('.element.name'),
elemsLen = $elements.length;
for (var i = 0; i < elemsLen; i++) {
var $theElem = $elements.eq(i),
elemOffset = $theElem.offset().top,
elemText = $theElem.html();
if (i > 0) {
topMargin = 39;
}
if (elemOffset < winScroll + topMargin) {
$resultBlock.html(elemText);
}
}
}
$(window).on('scroll', function() {
setResultText();
});
$(function() {
setResultText();
});
$(window).on('scroll', function() {
var winScroll = $(window).scrollTop(),
topMargin = 101,
$resultBlock = $('.result');
$('.element.name').each(function() {
var $elemName = $(this),
elemOffset = $elemName.offset().top,
elemText = $elemName.html();
if (elemOffset < winScroll + topMargin) {
$resultBlock.html(elemText);
}
});
});
animate
или через css-transitions иanimate
.Например, так: