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 trial
Matthew Walavich
176 PointsScroll only div not window
Trying to only scroll through the content inside the div not the whole window
$(document).ready(function() {
var pictureCount = picture.length;
var scrollResolution = 75;
function animateScroll() {
var currentScrollPosition = window.pageYOffset;
var imageIndex = Math.round(currentScrollPosition / scrollResolution);
if (imageIndex >= pictureCount) {
imageIndex = pictureCount - 1;
}
picture.hide();
picture.eq(imageIndex).show();
}
animateScroll();
$("#container").on("mouseover", _=> document.body.style.overflow = "scroll");
$("#container").on("mouseout", _=> document.body.style.overflow = "hidden");
$(window).on('scroll', function() {
animateScroll();
});
});
1 Answer
Steven Parker
243,318 PointsYou don't need JavaScript for this. Just this little bit of CSS will give you a scrollable container fixed on the screen:
#container {
position: fixed;
overflow-y: scroll;
width: /* photo width + 20px for scroll bar */;
height: /* photo height */;
}
I also posted this solution to your previous question.