I'm trying to create a seamless scroller for a page I'm building that has an internal scrolling div. Here's how I want it to work:
The process should work the same way in reverse. I thought using state might help. My three states are pre , on , and post . If you pass the threshold and your state is pre , it changes to on and the div "unlocks" for scrolling. Then, when you finish scrolling the div, it naturally pushes the entire page up. The state switched from on to post .
My problem is that if you scroll too speedily, the browser doesn't register these changes until it's too late, the div has already gone past. I wrote this code to manage the transition:
function onScroll() {
if (cur_coord > cap_y &&
cap_state == 'pre') { // Pre -> On
container.css({ 'overflow-y':'scroll'});
$(window).scrollTop(cap_y);
cap_state = 'on';
} else if (cur_coord > cap_y &&
cap_state == 'on') { // On -> Post
container.css({ 'overflow-y':'hidden'});
cap_state = 'post';
} else if (cur_coord < cap_y &&
cap_state == 'post') { // Post -> On
container.css({ 'overflow-y':'scroll'});
$(window).scrollTop(cap_y);
cap_state = 'on';
} else if (cur_coord < cap_y &&
cap_state == 'on') { // On -> Pre
container.css({ 'overflow-y': 'hidden'});
cap_state = 'pre';
}
}
and I've created a fiddle to play with:
Any thoughts one how I might make this a seamless scroll experience?
Thanks!
if you want to build your own scroller this is not an option. If you don't mind using a jQuery library... http://manos.malihu.gr/jquery-custom-content-scroller/
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.