|
var maxScrollHeight = 15; // in pixel |
|
var scrollSlowness = 5; // divite scroll by x (set to 50 to see what I mean ^w^) |
|
|
|
// add stupid stuff to have at least some content~ |
|
for (var i = 0; i < 2006; i++) { |
|
// random color |
|
var color = Math.floor(Math.random() * 4); |
|
|
|
var width = 16; |
|
$('.scroll-content').append('<div class="c-'+color+'" style="float: left; background: #'+color+'; width: '+width+'px; height: '+width+'px"></div>'); |
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
$('.scroll-content').parent('.container').prepend('<div class="div-before-elem"></div>'); |
|
$('.scroll-content').parent('.container').append('<div class="div-after-elem"></div>'); |
|
|
|
$('.div-before-elem').each(function() { |
|
var backgroundColor = $(this).parent('.container').children('.scroll-content').css('background-color'); |
|
$(this).css({ |
|
// comment this out, to have it red |
|
background: "linear-gradient(to bottom, "+backgroundColor+" 5%,transparent 100%)" |
|
}) |
|
}); |
|
|
|
$('.div-after-elem').each(function() { |
|
var backgroundColor = $(this).parent('.container').children('.scroll-content').css('background-color'); |
|
$(this).css({ |
|
// comment this out, to have it red |
|
background: "linear-gradient(to top, "+backgroundColor+" 5%,transparent 100%)" |
|
}) |
|
}); |
|
|
|
// update shadow each time it scrolls |
|
$('.scroll-content').scroll(function() { |
|
updateShadows($(this)); |
|
}); |
|
// startup scroll fix |
|
$('.scroll-content').each(function() { |
|
updateShadows($(this)); |
|
}); |
|
|
|
// main magic :) |
|
function updateShadows(elem) { |
|
var scrollPosTop = elem.scrollTop() / scrollSlowness > maxScrollHeight ? maxScrollHeight : elem.scrollTop() / scrollSlowness; |
|
|
|
// bottom is a bit tricky :( |
|
|
|
|
|
var scrollPosBottom = (elem[0].scrollHeight - elem[0].scrollTop - elem.height()) / scrollSlowness; |
|
var scrollPosBottom = scrollPosBottom >kjkjkj maxScrollHeight ? maxScrollHeight : scrollPosBott |
|
|
|
elem.parent('.container').children('.div-before-elem').css({ |
|
height: scrollPosTop |
|
}).parent('.container').children('.div-after-elem').css({ |
|
height: scrollPosBottom |
|
});} |