0

I'm trying to make ScrollView automatically scroll to the end of the whole element. I've noticed that

scrollview.setVelocity(-700);
// OR
scrollview.setPosition(1000);

will do the trick, but the amount required to get all the way to the end makes the view jump and go past too fast. If I use a smaller velocity the view will just jitter a bit in place.

Any way to make the view scroll to the end smoothly so that the user can see what's happening?

luopio
  • 507
  • 4
  • 14

2 Answers2

1

Was looking for how to stop the bounce on the scrollview and came across this question. It's been a little while so you've probably figured it out but figuring out the height of your scrollview and just using scrollview.setPosition(x) will set the scroll to that position. If you actually want it to "scroll" do scrollview.spring.setAnchor(x); and then set scrollview.setVelocity(x); its the combination of the two that makes it start to scroll. It will stop as soon as you click on the scrollview but thats usually not a bad thing.

aintnorest
  • 1,326
  • 2
  • 13
  • 20
  • Oh if your unsure how to get the size of the scrollview to know the height i think scrollview._scroller.getSize(); will return a size array. I don't have a project open to test. – aintnorest Sep 12 '14 at 22:16
  • Thanks for the clear instructions. Somehow ScrollView.setPosition(x), where x (~500) is from _scroller.getSize, the view bounces a bit down and then back up. With setAnchor I can slowly move the view down, but after 250 px it'll bounce up again. What kind of works is setPosition(10000) or setPosition(-10000), which will throw the view towards the end or the top, but that doesn't really provide good UX :(. Combo of setAnchor & setVelocity didn't help either. Can you verify it works for you so I can see if it's my famo.us setup? – luopio Sep 14 '14 at 10:21
  • I'm sorry whats ~ for? I use this now to scroll from the bottom to the top by using -x where x is the window.innerHeight value. Works great. I also use the scrollview from https://github.com/wgester/famous fork which my understanding will get merged into the main repo "soonish". Although it shouldn't change how this works. I tried testing and weirdly the size returns undefined, undefined which is odd since I can drill into the _scroller and find the size console it out but when I try consoling it out it also shows as undefined. – aintnorest Sep 15 '14 at 04:50
  • Sorry "~ 500" was shorthand just to say "about 500". I've setup a js-fiddle for this and I still get the same results with 10000 working and something less just causing a bounce effect: http://jsfiddle.net/luopio/knmLx/3/ – luopio Sep 15 '14 at 13:46
  • What version of famous are you using? if you scroll even a single pixel down before pressing the button it acts like it should. With the true height being 8000 and a velocity of 14ish will make it scroll nicely but only if you've scrolled. if you haven't it sticks as though the anchor is still set at 0 for some reason. I can't reproduce it on my version. – aintnorest Sep 15 '14 at 17:52
  • The 1px scrolling beforehand + setVelocity(14) + updating the Famo.us in the JSFiddle to use 0.2.0 did it. With previous versions the scrollview would jump to end too quickly or do nothing. The need to scroll before anything happens does not make this an ideal solution, but at least it works sometimes :) => working fiddle here http://jsfiddle.net/luopio/knmLx/8/ – luopio Sep 16 '14 at 08:24
0

Scrollview uses a spring internally. Just call setAnchor() to set the scroll target position. The spring will then smoothly moves the scroll area with transition.

Jens Zastrow
  • 287
  • 1
  • 3
  • 9
  • Tried scrollview.spring.setAnchor([1, 1, 1]) and scrollview.spring.setAnchor(1), replacing 1 with different numbers from 10000 to 0.1, but nothing happens. Could you please provide an example? – luopio Aug 25 '14 at 13:36