flickity icon indicating copy to clipboard operation
flickity copied to clipboard

Offset Tile - Wrap around delayed loading

Open MariuszDabrowski opened this issue 11 years ago • 6 comments

Hey David,

I'm trying to offset the tiles by 200px by adding transform: translateX(-200px);. As you scroll through you'll notice that the end tiles load in with a slight delay.

Is there someway that we can load in 2 tiles at the end or beginning to prevent this? Perhaps there is an easier solution to this issue?

https://codepen.io/MarioD/pen/vOWjar

Thanks, Mario

MariuszDabrowski avatar Jun 24 '15 18:06 MariuszDabrowski

I'm trying to offset the tiles by 200px

Can you explain what you're trying to achieve? Are you trying to align the cells a certain way? I think the best way to resolve this issue is to find a solution here.

desandro avatar Jun 24 '15 19:06 desandro

Hey David,

We are trying to align the first tile to the edge of our website container, where the titles appear.

Here's an example.

https://codepen.io/MarioD/pen/vOWjar

MariuszDabrowski avatar Jun 24 '15 19:06 MariuszDabrowski

Thanks for the demo! I think we can hack it. See http://codepen.io/desandro/pen/waPXRz

We have to overwrite how a Cell's .target works. We want it to be the left edge of the cell.

Flickity.Cell.prototype.setDefaultTarget = function() {
  var marginProperty = this.parent.originSide == 'left' ? 'marginLeft' : 'marginRight';
  this.target = this.x + this.size[ marginProperty ];
};

Next, we set cellAlign to a decimal that represents the space between the header element and the left edge

var leftOffset = ( $headingWrapper.parent().innerWidth() -  $headingWrapper.width() ) / 2;

var $gallery = $('.gallery');
$gallery.flickity({
  cellAlign: leftOffset / $gallery.innerWidth(),
  wrapAround: true
});

desandro avatar Jun 24 '15 20:06 desandro

That did the trick, thanks!

MariuszDabrowski avatar Jun 26 '15 18:06 MariuszDabrowski

For anyone else that wants to achieve this, it seems we should now be overriding Flickity.Cell.prototype.updateTarget instead of setDefaultTarget (the latter is getting deprecated). However, i couldn't get this behavior with the suggested tweaks, so downgraded my version of flickity to 1.1.

mcrider avatar Feb 14 '17 20:02 mcrider

Thanks for that hack, @desandro, exactly what I needed! 😊 Since it really doesn't seem to work with the latest versions any more, is there any chance for an updated hack?

zitrusfrisch avatar Jun 23 '17 21:06 zitrusfrisch