I want to achieve a similar effect seen in the game A Dark Room. The text in the game serves two purposes which I am trying to replicate:
- The new text is added above the old text instead of below it, pushing the older text down the page as the game progresses.
- As the text moves down the page, it gradually fades out of view.
I'm currently stuck on accomplishing #1. I believe using something like insertAfter
instead of
InsertBefore</code might be helpful, but I'm not sure.</p>
<p>My current code looks like this:</p>
<p><code>$("<p>You picked up a sword.</p>").hide().insertBefore("#placeholder").fadeIn(1000);
However, this inserts the new text below any existing text.
Regarding #2, I think placing the text inside a div and setting overflow: hidden
could work. I suspect there might be some JavaScript or CSS that can make it gradually fade out as it moves lower on the page. This is where I feel stuck.
I thought the following might hold the answer:
$(window).scroll(function () {
var scrollTop = $(window).scrollTop();
var height = $(window).height();
$('.logo_container, .slogan').css({
'opacity': ((height - scrollTop) / height)
});
});
I came across a fiddle here http://jsfiddle.net/0ma4na3t/1/ that somewhat achieves this effect with a div. However, I'm confused about where .slogan
comes from in that fiddle. It doesn't seem to appear in the code provided. Is it a jQuery or JS command?