harm-less / angular-sticky

Pure javascript AngularJS directive to make elements stick when scrolling

Home Page:http://harm-less.github.io/angular-sticky

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Listen to touchmove events for mobile scroll

psaniko opened this issue · comments

Thanks for this great plugin! We are currently trying to optimize for mobile devices and face the many challenges of mobile scrolling. A common kind-of-fix is to listen to touchmove events, maybe this could get an optional flag for the next release?

Can you give a small example of what you mean? Could be a demo, sample code or documentation.

I found it hard to write pseudo code for our use case, so I'll try to explain. On desktop the scroll event is fired multiple times during scrolling as expected. On mobile touch devices though, the scroll event is only fired when the scrolling is complete, that is you remove the finger from the screen and momentum scrolling has stopped. This results in a rather long delay for updating the stickyness.

Firing events during momentum scrolling is whole different topic but at least for moving the page there are the touchmove events which the plugin could listen to in addition to scroll events.

Demo for touchmove here: http://tomicloud.com/2012/03/multi-touch-demo

As an alternative way, maybe there could be an option to trigger an update of the sticky elements? I found the draw() method but I am not sure if this would be the right place.

I understand now and also you make a good point that made me realize something. You can use the draw method in order to bind you own touch events whatever that looks like.

I think from this demo it will become apparent what I mean. You then can bind other events than scroll that will call the draw method. The only downside is that you can no longer use the hl-sticky directive, but the result is the same.

Alright, we'll use the draw method then, thanks. Maybe custom callbacks on the h1-sticky directive can be put on the someday-later-list :)

Alright, they might be some day.
Perhaps you can show me some example code when you're done with the implementation, because it might inspire me to make features that have those callbacks supported.