虽然已经不用js方式了,但还是收藏一下nicescroll.js

 

<script type='text/javascript'>
var nsrOptions = {
"enabled":"1",
"cursorcolor":"#81d742",
"cursoropacitymin":"0.0",
"cursoropacitymax":"1.0",
"cursorwidth":"5px",
"cursorborderwidth":"0",
"cursorborderstate":"solid",
"cursorbordercolor":"#fff",
"cursorborderradius":"12px",
"background":"#f7f7f7",
"scrollspeed":"45",
"mousescrollstep":"40",
"autohidemode":"on",
"zindex":"9999",
"hwacceleration":"1",
"usetransition":"1",
"cursorminheight":"32",
"preservenativescrolling":"1",
"railoffset":"off",
"bouncescroll":"1",
"spacebar":"1",
"railpaddingtop":"0",
"railpaddingright":"0",
"railpaddingbottom":"0",
"railpaddingleft":"0",
"disableoutline":"1",
"horizrailenabled":"1",
"railalign":"right",
"railvalign":"bottom",
"enablemousewheel":"1",
"enablekeyboard":"1",
"smoothscroll":"1",
"sensitiverail":"1",
"enablemouselockapi":"1",
"cursorfixedheight":"160",
"directionlockdeadzone":"6px",
"hidecursordelay":"400",
"nativeparentscrolling":"1",
"overflowx":"1",
"overflowy":"1",
"cursordragspeed":"0.5",
"defaultScrollbar":"",
"touchbehavior":"",
"grabcursorenabled":"",
"rtlmode":"",
"cursordragontouch":"",
"view":"frontend"};
</script>
<script type='text/javascript' src='//cdn.bootcss.com/jquery.nicescroll/3.7.0/jquery.nicescroll.min.js'></script>
<script type='text/javascript' src='./js/nicescroll.js'></script>
<script type="text/javascript">
	if ($("#main").height() > $("#sidebar").height()) {
		var footerHeight = 0;
	   if ($('#page-footer').length > 0) {
		footerHeight = $('#page-footer').outerHeight(true);
				}
			$('#sidebar').affix({
				offset: {
				top: $('#sidebar').offset().top - 30,
				bottom: $('#footer').outerHeight(true) + footerHeight + 6
					}
				});
			}
</script>

更新于:2017-11-21