Closed urbien closed 10 years ago
Based on the ideas above Mark has made a first cut of the infinite scroll with bounces which uses PhysicsJS. Here it is applied to a concept app Trees, which we worked on for the Department of Recreation in NYC. Note that the amount of resources in this demo is about 600k so you can scroll till you are blue in the face. Note that although images look the same they all have different URLs so it is a realistic demo. To test bottom bounce go to smaller lists, like App Gallery and Ideas Gallery at Urbien App home. The cool part of this demo is that it is a masonry, so it combines a layout manager, a sliding window manager and physics engine and runs them in a #6 worker thread.
There is some polishing to do still. Drag and release is not ideal yet, will work on it tomorrow. But the main problem is that bounces are too bouncy. If we increase stiffness they becomes small in amplitude but still bounce too much. If we decrease stiffness, it starts to bounce so long and with such amplitude that it soon gets on your nerves. Seem like we need to tune some variable other than stiffness of the constraint.
You might be looking to an analog of energy dissipation. You could try modifying the verlet constraint behavior to reduce the relative velocities when constraints are resolved by some input factor. You could also try modifying the "drag" coefficient on the integrator dynamically as you need it.
Thanks. Mark added linear damping proportional to velocity. He found it on the site physics labs and then noticed that p2.js does it this way. It worked out perfectly.
This issue has been discussed over email and I will try to summarize the ideas my Ellen, Mark and me below. All the work so far was done with physics.js. Great thanks to its creator Jasper for lending his expertise and suggesting ways to use his physics.js for momentum scrolling with bounce.
Problem
Scroller needs to freely move the contents of the page until the tail of the content reaches the edge of the scroll areas (not edge of the screen, as we need fixed top and bottom headers). When the tail of the scrolled content passes the edge it needs to bounce back to the edge and move a bit past it (and repeat the bounce with the smaller amplitude). We need a physical world model for such behavior. A constraint does not work here as it will prevent the movement in both directions. We need this to work for both vertical scrolls and for the horizontal scrolls, like the photo strip inside the page, like in IMDB app they let user scroll movie shots horizontally while still standing on a movie page.
Once implemented we will use it also for a mobile drawer (left/right side menu) transition, and probably for many more cases. So below are some imperfect ideas, may be you can shut them down and suggest something better.
Ideas
Discussion with Jasper and Mark
So, when user flicks in the opposite direction, we will break the constraint (by removing it) at the same distance (threshold) at which we added it. But we should let dev set the second distance manually.
We would also need to check not just the distance, but also a direction. As users can flick in both directions but break it only in one.
we r thinking to add things like: c.breakOnDistance(distance1, direction /* optional /, distance2 / optional / ) for to make it flexible, also: c.breakon(function breakTest1(body) {}) / allows dev to add his own condition checks for pos, speed, acceleration, and later for color, scale, etc. etc. */
eg:
var range = Physics.aabb( x1, y1, x2, y2 ); c.breakOutside( range );
// breakOutside implements... if ( ! this.range.contains( this.body.state.pos ) ){ // break the constraint