jQuery Scrolling Box

$('.dn').mousedown(function(event) { mouseisdown = true; ScrollDown(); }).mouseup(function(event) { mouseisdown = false; });
function ScrollDown(){ //var topVal = $('.up').parents(".container").find(".content").css("top").replace(/[^-\d\.]/g, ''); var topVal = $(".content").css("top").replace(/[^-\d\.]/g, ''); topVal = parseInt(topVal); console.log($(".content").height()+ " " + topVal); if(Math.abs(topVal) < ($(".content").height() - $(".container").height() + 60)){ //This is to limit the bottom of the scrolling - add extra to compensate for issues $('.up').parents(".container").find(".content").stop().animate({"top":topVal - 20 + 'px'},'slow'); if (mouseisdown) setTimeout(ScrollDown, 400); }
$('.container').mousewheel(function(event, delta, deltaX, deltaY) { // console.log('mouse'+ delta, deltaX, deltaY); if(delta < 0){ //Scroll down var topVal = $('.up').parents(".container").find(".content").css("top").replace(/[^-\d\.]/g, ''); console.log('lol'); topVal = parseInt(topVal); $('.up').parents(".container").find(".content").stop().animate({"top":topVal + (deltaY * 10) + 'px'},'slow'); } if(delta > 0){ //Scroll up var topVal = $('.up').parents(".container").find(".content").css("top").replace(/[^-\d\.]/g, ''); topVal = parseInt(topVal); $('.up').parents(".container").find(".content").stop().animate({"top":topVal - (-deltaY * 10) + 'px'},'slow'); } });

--

--

I enjoy building software, making web applications, surfing, snowboarding and cooking!

Love podcasts or audiobooks? Learn on the go with our new app.

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store