iscroll icon indicating copy to clipboard operation
iscroll copied to clipboard

Momentum on mousewheel

Open fmay opened this issue 11 years ago • 9 comments

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.

fmay avatar Jun 03 '13 17:06 fmay

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

cubiq avatar Jun 03 '13 17:06 cubiq

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

fmay avatar Jun 03 '13 18:06 fmay

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.

cubiq avatar Jun 05 '13 09:06 cubiq

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

jordanaustin avatar Jun 11 '13 23:06 jordanaustin

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.

cubiq avatar Jun 12 '13 09:06 cubiq

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?

lingz avatar Aug 21 '13 12:08 lingz

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

thehappycoder avatar Nov 18 '14 10:11 thehappycoder

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);
}

roman-vabishchevych avatar May 26 '17 08:05 roman-vabishchevych

@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?

cbravo avatar Jul 18 '17 20:07 cbravo