cubiq / iscroll

Smooth scrolling for the web
http://iscrolljs.com
MIT License
12.88k stars 3.82k forks source link

Momentum on mousewheel #374

Open fmay opened 11 years ago

fmay commented 11 years ago

Matteo - you asked for some test results, here are mine on Chrome 27.0.1453.93 on Mac

I did this video that applies to the first demo example (http://lab.cubiq.org/iscroll5/demos/simple/) : http://screencast.com/t/SsGCslpsmb

It works great when dragging but when you use the mouse wheel (mor magic mouse in my case) you lose the nice mometnum slow-down effect when using the mouse wheel. I may be missing the point, but thought it is worth mentioning.

Other than that, love it. Can't wait to try it on mobile device.

cubiq commented 11 years ago

thanks for your report, this is something I also noticed but it's not easy to solve. Some trackpad firmwares already add momentum/deceleration so it wouldn't be easy to mix software and hardware deceleration. I have to dig deeper into this

fmay commented 11 years ago

Not a big problem, but would be great if do-able.

cubiq commented 11 years ago

I've added back momentum with trackpad. It's a bit more complicated to add the same behavior with mouse wheel. I'm keeping this open.

jordanaustin commented 11 years ago

I notice this problem a lot on the Microsoft Surface keyboards built-in trackpads. Magic mouse works nicely and as expected.

cubiq commented 11 years ago

some devices have deceleration built in, others don't. this has a low priority for now, but it's definitely something I want to explore.

lingz commented 10 years ago

For the acceleration, you can check the delta values and the rate they are coming in right? So with some magickry, you could potentially guess it's acceleration and adjust accordingly?

thehappycoder commented 9 years ago

Currently we use iscroll 5 on mobile devices and this issue prevents us from using it on desktop devices.

roman-vabishchevych commented 7 years ago

Hi guys! You can use TweenMax for smooth scrolling.

const wrapperNode = document.querySelectorAll(".scroll-wrap");
if (wrapperNode.length > 0) {
    const wrapper = wrapperNode[0];
    const iScrollInstance = new IScroll(wrapper, {
        scrollbars: true,
        interactiveScrollbars: true,
        mouseWheel: false,
        click: true
    });
    let scrollTop = -iScrollInstance.y;
    let wrapperScrollHeight = wrapper.scrollHeight;
    const updateIScrollHeight = () => {
        if (wrapperScrollHeight != wrapper.scrollHeight) {
            wrapperScrollHeight = wrapper.scrollHeight;
            setTimeout(() => {
                iScrollInstance.refresh();
            }, 0);
        }
    };
    const doScrolling = event => {
        event.preventDefault();
        updateIScrollHeight();
        const scrollTime = 0.5;
        const scrollDistance = 120;
        const delta = event.wheelDelta / 120 || -event.detail / 3;
        scrollTop = scrollTop - parseInt(delta * scrollDistance);
        scrollTop = Math.max(0, Math.min(wrapper.scrollHeight - window.innerHeight, scrollTop));
        const cfg = { y: scrollTop };
        TweenMax.to(cfg, scrollTime, { y: scrollTop, ease: Power1.easeOut, onUpdate: () => {
                iScrollInstance.scrollTo(0, -cfg.y, 0);
            }
        });
    };
    window.addEventListener('load', updateIScrollHeight);
    document.addEventListener("mousewheel", doScrolling);
    document.addEventListener("DOMMouseScroll", doScrolling);
}
cbravo commented 6 years ago

@roman-vabishchevych @cubiq Is there a reason not to simply put transition-duration: 0.5s !important; on the scroller div and scroll indicator in order to achieve smooth scrolling?