Skip to content
This repository has been archived by the owner on Mar 27, 2019. It is now read-only.

Add ability to scroll to elements with offsets. #118

Closed
wants to merge 5 commits into from

Conversation

ppicazo
Copy link

@ppicazo ppicazo commented Sep 16, 2011

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.

@dsamuels
Copy link

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?

@cubiq
Copy link
Owner

cubiq commented Sep 16, 2011

Note sure if this should end up in the core... waiting for feedback

@ppicazo
Copy link
Author

ppicazo commented Sep 16, 2011

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

@ppicazo
Copy link
Author

ppicazo commented Sep 17, 2011

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

@cubiq
Copy link
Owner

cubiq commented Sep 17, 2011

I see, what do you think of a "centered" parameter that if true centers the object in the screen?

@dsamuels
Copy link

options.centered would be great!

@francoisromain
Copy link

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

@cubiq
Copy link
Owner

cubiq commented Sep 17, 2011

@francoisromain scrollto accepts relative values

@francoisromain
Copy link

@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.
If iScroll had this offset option, i could use only this for both desktop and iOs.

@cubiq
Copy link
Owner

cubiq commented Sep 17, 2011

iscroll has scrollTo with relative offset

@ppicazo
Copy link
Author

ppicazo commented Sep 17, 2011

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

@francoisromain
Copy link

@ppicazo actually i didn't understand @cubiq's message and i was refering to jquery.scrollTo.

like you said, for my problem, i'd like to use scrollToElement with an offset setting.

@ppicazo
Copy link
Author

ppicazo commented Oct 3, 2011

@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.
@ppicazo
Copy link
Author

ppicazo commented Dec 21, 2011

Three months since last response from @cubiq on this. Unless there is some activity relatively soon, I'll close this pull request.

@cubiq
Copy link
Owner

cubiq commented Dec 21, 2011

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.

@ppicazo
Copy link
Author

ppicazo commented Dec 21, 2011

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

@nicam
Copy link

nicam commented Sep 12, 2012

would love to have it centered too

@designbyadrian
Copy link

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
that.scrollTo(pos.left, pos.top, time);
into
that.scrollTo(pos.left, pos.top, time, true);

Sneaky, Cubiq!

@cubiq
Copy link
Owner

cubiq commented May 14, 2013

this is not going to be included in iScroll 4, but it will end up in iScroll 5. Thanks everyone for the feedback

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

6 participants