jquery cycle link from external page to specific s

2019-07-01 23:33发布

Been perusing all the other questions, and I can't figure this out. I have a home page that features certain slides from another page I have using the jquery cycle plugin. What I need to do is have the link on the home page link directly to a slide that isn't the first slide of a group. Nothing that complicated. I have a link like this on my home page:

<a href='portfolio.php'>SEE MORE</a>

I've looked into adding named anchors using the pagerAnchorBuilder and then referencing that anchor in my link. Successfully adds named anchors:

   pagerAnchorBuilder: function(idx, slide) {
    return '<li'+s+'><a href="#" name="portfolio'+(idx+1)+'">'+(idx+1)+'</a></li>';
    }

But linking to them does nothing. Ex:

<a href='portfolio.php#portfolio3>SEE MORE</a>

I'm thinking this is related to updateActivePagerLink. Is there a way to somehow have the named anchor tell the page with cycle which slide to make active? Or is there another approach that is easier? Seems like this would be a common application! I'm a beginner at jQuery. Can't figure it out!

1条回答
成全新的幸福
2楼-- · 2019-07-02 00:15

You can do this by adapting the poor man's pager jQuery Cycle example. In this JSFiddle, I've taken that code and changed it to use links rather than buttons.

It checks on page load for an anchor ID and, if it finds one, send a click event to the relevant element.

    if (location.hash)
    {
        $('#' + location.hash.substring(1)).click();
    }
查看更多
登录 后发表回答