Add ability to scroll to elements with offsets. #118
Conversation
Thanks for your work on this! Maybe I am missing something, but it does not seem to work for horizontal lists. List items at the start or end of the list will not be scrolled to the center because of bounds checking that takes place in scrollToElement and other places. Can you confirm that this is the case? |
Note sure if this should end up in the core... waiting for feedback |
@dsamuels: You are correct. It is simply an offset to add/subtract from the end position calculated for the element. When an item is the first in the list it will not be centered. |
@cubiq We've used jQuery.ScrollTo previously and found the offset for scrolling to elements useful. Typically we direct the user to an element on the scrollable area and it's nice to have it in the center of their view to interact with. I thought this (offsets) would be a common use of scrollToElement, but perhaps not. |
I see, what do you think of a "centered" parameter that if true centers the object in the screen? |
options.centered would be great! |
@cubiq for an horizontal scroll, i wish i could define a left offset (to replace jquery.scrollto and do something like this : http://tinyurl.com/3l49ccu) |
@francoisromain scrollto accepts relative values |
@cubic i am not sure about scrollto accepting relative values. Scrollto is working fine on desktop, but not on iOs. I have to use iScroll for iOs. |
iscroll has scrollTo with relative offset |
@francoisromain, are you referring to scrollToElement or scrollTo? @cubiq, I can understand the desire to center the element via a boolean, but at least in our case, we do not want to scroll the X axis. And there are probably people who might not want use the offset for something other than the center. With scrollTo() you can make any offset adjusts in the x & y values themselves. For scrollToElement() without being able to specify offsets you are left with using scrollTo() and calculating the position of the element yourself. |
@cubiq any decision on this yet? |
* upstream/master: Allow wheelAction to be none. HP TouchPad support clean up Edited src/iscroll.js via GitHub bitwise operator instead of Math.round
* upstream/master: Commit 43bacc2 broke iscroll for some Android devices, check against zoom boolean, not function
* upstream/master: cancelAnimationFrame update scrolltopage allows 0 as time Corrected the conditional to fix a leak.
Three months since last response from @cubiq on this. Unless there is some activity relatively soon, I'll close this pull request. |
sorry ppicazo, I've been really busy and I have to check that all pull requests work in concert. I'll work on it in this holiday break. thanks for your support and for your patience. |
@cubiq understable, no worries, I appreciate all your work on this project. Just didn't want to keep it open / current if there was no chance of it being merged. |
would love to have it centered too |
It seems that it CAN scroll to, and centre! looking into iScroll 4.2.5, the scrollTo method takes [left:number, top:number, time:number, relative:boolean] if relative is true, it will centre on the object! So what do you do? Find the function scrollToElement in iScroll.js, or go directly to line 1009. Change Sneaky, Cubiq! |
this is not going to be included in iScroll 4, but it will end up in iScroll 5. Thanks everyone for the feedback |
For our use case, we need the ability to center on the target element. If this is useful to the community, please pull it in. Thanks for the work you've put in to this project.