JSFiddle - React, Tailwind, and code Playground

by nhuon

JavaScript

$(document).load(function()
{
	$(".scroll-follow").each(function() {
		var element = $(this);
		element.data('window_top', element.offset().top);
	});

	$(window).scroll(function() {
		$(".scroll-follow").each(function() {
			var element = $(this);
			var element_top = element.data('window_top');
			var window_top = $(window).scrollTop();
			console.log(window_top);
			console.log(element_top);
			var position = element_top - window_top;
			console.log(position);
			if (position < 10) {
				element.css({
					'margin-top': window_top - element_top + 10
				});
			}
		})
	});
});