darsain / sly

JavaScript library for one-directional scrolling with item based navigation support.
http://darsa.in/sly
2.87k stars 497 forks source link

Unactivate item... #203

Closed misawsneto closed 9 years ago

misawsneto commented 9 years ago

Is there a way to unactivate a page. On init, the property startAt is null. I want to unactive the current page programmatically.

darsain commented 9 years ago

No. Page is just an indicator of what page is Sly scrolled at right now. There is no concept of un-activating a page.

misawsneto commented 9 years ago

So, once a page is set there is no way to unset a page programmatically? I'm having a tough time with click events. And i'm using active event in order to select a page and do some business logic. But once I click, the page is set and cannot reactivate that page. If I use ordinary click events instead of active I get unwanted selection while scrolling and navigating while using mouseDragging & touchDragging.

makes sense?

darsain commented 9 years ago

Yeah, making interactivity work with dragging is a game of compromises. If you want to implement something that doesn't come with Sly out of the box and relies on clicking on items while dragging is enabled, prepare for a pretty frustrating coding session.

misawsneto commented 9 years ago

Ok. I think the best way to do this is by leveraging the active event and once the event is triggered programmatically unactivate the page. Could you point me to any point in the code where I can try to implement this?

Another hacky way of doing this is by creating an invisible item at the end of the list and set it to active mode. The problem I'm having whith that is the scroll automaticly moves to the last item. Can I set an item to active and retaing scroll position?

BTW, this a very awesome library.

darsain commented 9 years ago

Don't modify Sly. Just disable Sly's active item handling (don't set activateOn option), and implement item activation by yourself the way it suits you, using Sly's API (documentation in docs directory) for stuff like "animate item to center when activated".

misawsneto commented 9 years ago

Ok, thanks. I solved this by adding a invisible item at the end of the list. I used the active event to capture clicks and once callback is triggered I'll set the last (invisible) item to active by doing sly.active(sly.items.length - 1). By doing this I can click on the same item once again.