From our sponsor: Meco is a distraction-free space for reading and discovering newsletters, separate from the inbox.
Today we’d like to share a little script that lets you navigate through a stack of thumbnails with an elastic touch. The idea comes from this Dribbble shot by CreativeDash and the interaction is basically dragging an item up to the point that it “releases” from the stack which it seems to be connected to with an invisible elastic. For the dragging functionality we are using David DeSandro’s Draggabilly.
Three items are visible initially, the main one and the the two next ones, which can be seen because we’ve added some perspective to the item list and translated the two items on the Z-axis. When dragging the top-most item, we’ll also drag those two items along creating the elastic illusion.
The HTML structure that we are working with is the following:
<ul id="elasticstack" class="elasticstack"> <li><img src="img/1.jpg" alt="01"/><h5>Saudade</h5></li> <li><img src="img/2.jpg" alt="02"/><h5>Tuqburni</h5></li> <li><img src="img/3.jpg" alt="03"/><h5>Retrouvailles</h5></li> <li><img src="img/4.jpg" alt="04"/><h5>Onsra</h5></li> <li><img src="img/5.jpg" alt="05"/><h5>Mamihlapinatapai</h5></li> <li><img src="img/6.jpg" alt="06"/><h5>Koi No Yokan</h5></li> </ul>
Tiny break: 📬 Want to stay up to date with frontend and trends in web design? Subscribe and get our Collective newsletter twice a tweek.
When the first item gets dragged, we’ll want it to bounce back if it’s dropped too close to the stack. That distance can be define in the variable distDragBack
. The area that will make the item disappear when dropped into is defined by the distance set as distDragMax
. Dragging the item beyond that distance will automatically release the item from the stack, no dropping necessary. This graphic shows the distances:
And this is how you can initialize the script:
new ElastiStack( element, { // distDragBack: if the user stops dragging the image in a area that does not exceed [distDragBack]px // for either x or y then the image goes back to the stack distDragBack : 200, // distDragMax: if the user drags the image in a area that exceeds [distDragMax]px // for either x or y then the image moves away from the stack distDragMax : 450, // callback onUpdateStack : function( current ) { return false; } } );
The beautiful illustrations used in the demo are by talented artist Guzk. They belong to the set Memoria de Ataun. Check out the artist’s Behance portfolio and website. Contact us if you’d like to be featured in one of our demos.
We hope you enjoy this experiment and find it useful!
I love it! I think I saw a similar effect somewhere a while ago and thought about recreating it but then completely forgot about it. =p
I also love the images you’re using! <3
it’s so beautiful,i like it
Nice sample. Would you like to move elastiStack.js to GitHub?
It is on GitHub, see the link in the end of the article 🙂
Fantastic Mary Lou as always !!!!! THX for this amazing tut
Amazing!
I wish I could have your imagination
I have learnt so much from you. Thanks to you and all of your TUTs.
WoooooW! Really great work!!!! thanks to share!!!
Woww!! awesome example, nice work!
Mary! Incrivelmente!
thanks
very nice
i enjoy to use it
thanks again
Mary Lou
Manoela thank you very much, you are great!
Nice work! In google chrome work bad, but in IE work fantastic! 😀
Wonderful!
How can I place more than four pictures in each BookBlock of demo5?
Thanks!
Works fine in Chrome for me.
Beautiful work! Thanks for sharing!
Hi Mary Lou, it’s a amazing work! Tks very much for sharing! I was thinking (not try yet), if there is a way to put some “next” and “back” buttons, so, we can drag the image or click on buttons to move to next photo or go back! I was thinking about that because we can move forward on gallery, but if are some photo that we want to see, we need to go through all gallery! If someone has some highlights thoughts about that, plz share =)
Hi!
Very nice script! Congratulations!
There is also the possibility to make it work on IE8?
I met a couple of problems:
the first, which I resolved, you add the method “call” on that ie8 does not exist in this way:
(function() { if(navigator.appVersion.indexOf('MSIE 8') > 0) { var _slice = Array.prototype.slice; Array.prototype.slice = function() { if(this instanceof Array) { return _slice.apply(this, arguments); } else { var result = []; var start = (arguments.length >= 1) ? arguments[0] : 0; var end = (arguments.length >= 2) ? arguments[1] : this.length; for(var i=start; i<end; i++) { result.push(this[i]); } return result; } }; } })();
the second, which I can not fix, it is a mistake “Message: Object doesn’t support this property or method Line: 138 Char: 5” at line 138:
instance.element.removeEventListener( transEndEventName, onEndTransFn );
There is a hack to make this wonderful plugin for ie8?
thanks
Hi It is really nice on. Can you help me to remove the swiped slides data from stack?
Really nice project. I am in a problem with this. I want to get first slid in different background color. How can I do that? Please help me.
Hello,
It is really nice work, and like it. Could you please help me to add LEFT & RIGHT Arrows ( Button ) for the transition to left and right accordingly.
I would like to add two button/arrow actions other than the swiping events.
Hi,
Its Really Great Script. Can you help me to integrate the left and right button click functionality to this application
Hi guys, if you are looking to detect whether a swipe is going left or right, follow these steps :
STEP 1 : Open elastiStack.js
STEP 2 : Find
ElastiStack.prototype._onDragEnd
STEP 3 : Replace the whole function with the one below :
ElastiStack.prototype._onDragEnd = function( instance, event, pointer ) { if( this._outOfBounds( instance ) ) { // FOR IF OUT OF BOUNDS DRAG if(instance.position.x > 0){ // RIGHT } else{ // LEFT } return; } if( this._outOfSight(instance) ) { // FOR OUR OF SIGHT DRAG this._moveAway( instance ); if(instance.position.x > 0){ // RIGHT } else{ //LEFT } } else { this._moveBack( instance ); } };
Enjoy.
hi,
Is Elastic Stack working for android version 4.1.2? Actually i tried to work on mobile default browser or in my apk.
But its not working. Can somebody help me out.
Thank you so much for sharing this. This was how I modified it. (I made sure to link back to this page on the mod and on github.)
http://tracyparker.github.io/ElasticStack-WhiteFlowers/
tengo un problema al implementarlo con AngularJS, en el ng-repeat, intento mostrar las imágenes de forma dinámica pero no me muestra nada. Por favor espero me puedan ayudar. 🙂
This is a great plugin. Though I am having problems when using it with requireJS. I notice that this is not also compatible with the latest draggabilly plugin (v1.2.4).
I’m getting this error.
Error: Script error for: get-style-property/get-style-property http://requirejs.org/docs/errors.html#scripterror
And it seems that it is loading “get-style-property/get-style-property.js” defined in draggabilly.
Any help? Thanks!
Hey ML,
This is neat! thanks alot, I hope that one day I can be as usefull with my code as you are to me and I am sure many others.
Good evening,
I wanted to make two rolls of photos and add one more tags with photos. Unfortunately it didn’t work. it leaves some space for this roll of photos ,but they aren’t visible. Can anyone help me to solve this problem.
Thank you in advance!