cycle2 icon indicating copy to clipboard operation
cycle2 copied to clipboard

Bookmarkable slides issue (hash change not always updating slide)

Open traummmaschine opened this issue 13 years ago • 3 comments

I'm using Cycle2 and need to use an external pager, completely custom existing markup (i.e. not able to use Cycle2's built in pager function, unfortunately!)

I'm wondering why separate 'pager' style links aren't always updating the slide (though always update the URL) - confusingly, some work and others don't...

I've set up a jsBin to try and illustrate my issue -

http://jsbin.com/aqusom/2

Is there anyway of forcing a refresh of the cycle slide on clicking these links?

Many thanks in advance for any help.

traummmaschine avatar Jul 25 '13 15:07 traummmaschine

Good catch @rickts , thanks!

malsup avatar Jul 26 '13 02:07 malsup

Thanks for fixing this up so quickly! :+1:

The latest version of the js however has knocked my callbacks out of sync, it seems - here's a very quick example:

http://jsbin.com/aqusom/10

Assuming this was a fix elsewhere along the line - I need the callback to target the newly-loaded in slide, but it's targeting the previous one... sure I've missed something but this callback was working with an older version of your script.

Sorry for resurrecting this issue, and thanks again for your help!

traummmaschine avatar Jul 26 '13 20:07 traummmaschine

You could change that code to use the cycle-update-view event:

$('.cycle-slideshow').on('cycle-update-view', function(e, opts) {
    imgCaption = $('.cycle-slide-active').attr('alt');
    $('.caption').html(imgCaption);
});

But a better way to approach this is to use Cycle2's declarative capabilities which requires no code at all:

<div class="cycle-slideshow" 
  data-cycle-timeout="0" 
  data-cycle-caption=".caption"
  data-cycle-caption-template="{{alt}}"
  >
    <img src="http://jquery.malsup.com/cycle2/images/p1.jpg" data-cycle-hash="redflower" alt="Caption of the red flower" />
    <img src="http://jquery.malsup.com/cycle2/images/p2.jpg" data-cycle-hash="trees" alt="Tree caption" />
    <img src="http://jquery.malsup.com/cycle2/images/p3.jpg" data-cycle-hash="ocean" alt="Caption of the ocean image" />
    <img src="http://jquery.malsup.com/cycle2/images/p4.jpg" data-cycle-hash="boat" alt="Boat caption" />
</div>

malsup avatar Jul 31 '13 17:07 malsup