I have made some jQuery Fallback Support for the CSS Property "background-attachment: local" and I am mainly a CSS developer. I do some jQuery, but I thought I would check to see if I am doing this in the more efficient way, as I may have multiple versions of this on one page.
HTML
<div class="container">
<div class="data-holder">
<div id="shadowtop"></div>
<div id="shadowbottom"></div>
<div class="block">hello</div>
<div class="block">hello</div>
<div class="block">hello</div>
<div class="block">hello</div>
<div class="block">hello</div>
<div class="block">hello</div>
<div class="block">hello</div>
<div class="block">hello</div>
<div class="block">hello</div>
<div class="block">hello</div>
<div class="block">hello</div>
<div class="block">hello</div>
<div class="block">hello</div>
<div class="block">hello</div>
<div class="block">hello</div>
<div class="block">hello</div>
<div class="block">hello</div>
<div class="block">hello</div>
<div class="block">hello</div>
<div class="block">hello</div>
<div class="block">hello</div>
<div class="block">hello</div>
<div class="block">hello</div>
<div class="block">hello</div>
<div class="block">hello</div>
<div class="block">hello</div>
<div class="block">hello</div>
<div class="block">hello</div>
<div class="block">hello</div>
<div class="block">hello</div>
</div>
</div>
CSS
@import "http://fonts.googleapis.com/css?family=Open+Sans:400,600,700";
* {
-moz-box-sizing: border-box;
-webkit-box-sizing: border-box;
box-sizing: border-box;
}
body {
background: none repeat scroll 0 0 #fff;
font-family: "Open Sans";
line-height: 26px;
margin: 20px;
}
.container {
position: relative;
margin-top: 30px;
}
.data-holder {
border-top: 1px solid #eee;
border-bottom: 1px solid #eee;
width: 200px;
height: 300px;
overflow: auto;
}
#shadowtop,
#shadowbottom {
position: absolute;
left: 0;
height: 12px;
width: 180px;
z-index: 9999;
display: none;
background-size: 100% 12px;
}
#shadowtop {
top: 0;
background: radial-gradient(farthest-side at 50% 0, rgba(0,0,0,.15), rgba(0,0,0,0)) 0 100%;
}
#shadowbottom {
bottom: 0;
background: radial-gradient(farthest-side at 50% 100%, rgba(0,0,0,.15), rgba(0,0,0,0)) 0 100%;
}
.block {
background: #fff;
border-bottom: 1px solid #f4f4f4;
padding: 10px;
}
.block:last-child {
border-bottom: 0 none;
}
jQuery
$(document).ready(function(){
$('.data-holder').scroll(function(){
var scrollValue = $(this).scrollTop();
var elementHeight = $(this).height();
if(scrollValue == 0){
$("#shadowtop").fadeOut(200);
console.log("at top"); //should remove
} else if (scrollValue == ($(this).get(0).scrollHeight - $(this).height())){
$("#shadowbottom").fadeOut(200);
console.log("at bottom"); //should remove
} else {
console.log("in middle"); //should remove
$("#shadowtop").fadeIn(200);
$("#shadowbottom").fadeIn(200);
}
});
var scrollValue = $('.data-holder').scrollTop();
if(scrollValue < ($('.data-holder').get(0).scrollHeight - $('.data-holder').height())){
$("#shadowbottom").show();
}
});