jquery cycle link from external page to specific slide?

橙三吉。 提交于 2019-12-10 19:29: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:


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();
    }


来源:https://stackoverflow.com/questions/5463649/jquery-cycle-link-from-external-page-to-specific-slide

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!