简体   繁体   中英

Show jQuery cycle slide by using #hash/anchor, not numbers

I'm working on a one page layout site, where I use jQuery Cycle to switch between content.

Currently I've changed the script so it displays the current slide in the URL (to make it possible to Favorite the current slide).

I've also made it possible to Alert the right ID, but I can't get it to activate the slide-function/effect.

$(window).bind('hashchange', function () { //detect hash change
        var hash = window.location.hash.slice(1); //hash to string (= "myanchor")
        alert(hash); //This Alerts the right ID/anchor of the current slide
        //$('.slideshow').cycle(hash); // This doesn't work. If I use 1, 2, 3 etc. it shows the diffent slides
    });

How can I get this to work? Am I missing something?

Thank you in advance.

I have not done it yet, but am about to try out this solution: http://wesbos.com/jquery-cycle-link-within-hashchange/

Edit: works like a charm!

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM