Welcome to the Treehouse Community
Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.
Start your free trialJoseph McClellan
4,045 PointsNeed help with scrolling divs with mouse and UI arrows
If you take a look at this page:
http://174.121.8.194/~unab/practice/special-medical-needs-shelter/
You'll notice that if you hover your mouse over the post content that you can scroll through it. You'll also notice the arrows just to the bottom-right of the post content. The arrows are currently non-functional but the client wants them to be able to be used to scroll through the content along with the mouse. Previously I thought they just wanted the arrows and no mouse scrolling so I found this piece of javascript to do that...
Scrolling post content
var total = $("#inner").outerHeight();
var step = 15;
function scrollUpFunction() {
if(parseInt($("#inner").css('marginTop')) >= -(total)+20) {
$("#inner").css('marginTop', parseInt($("#inner").css('marginTop'))-step);
$("#down").css('color', '#9a9a9a');
} else {
$("#up").css('color', 'red');
}
}
function scrollDownFunction() {
if(parseInt($("#inner").css('marginTop')) <= 0) {
$("#inner").css('marginTop', parseInt($("#inner").css('marginTop'))+step);
$("#up").css('color', '#9a9a9a');
} else {
$("#down").css('color', 'red');
}
}
$("#down").mousedown(function() {
scrollUpInt = setInterval(scrollUpFunction, 100);
}).mouseup(function() {
clearInterval(scrollUpInt);
});
$("#up").mousedown(function() {
scrollDownInt = setInterval(scrollDownFunction, 100);
}).mouseup(function() {
clearInterval(scrollDownInt);
});
Since they want both the mouse and the arrows to scroll the content, is there a way I can edit this code to make it work? Right now you'll notice it scrolls the margin (which hides the content)... but that's problematic for obvious reasons when scrolling with the mouse as well.
2 Answers
Joseph McClellan
4,045 PointsWould still love to hear some solutions on this, but just in the interest of full disclosure it looks like I may have found a new solution.
Joseph McClellan
4,045 PointsYup. After some tinkering I finally got scrollTo working.