简体   繁体   English

链接到jquery滑块的特定幻灯片

[英]Link to a particular slide of a jquery slider

So I'm using a very basic jquery slider (see a sample in action on this JSFiddle ). 因此,我使用了一个非常基本的 jquery滑块(请参阅对此JSFiddle进行操作的示例)。 I can click on links ("Slide A," "Slide B," "Slide C") on the page with the content slider to slide between the slides. 我可以使用内容滑块单击页面上的链接(“幻灯片A”,“幻灯片B”,“幻灯片C”)在幻灯片之间滑动。 What I would like to be able to do is allow a visitor to click on "Slide B" from another page on the website, which would link to the page containing the slider, and then show Slide B. 希望能够做的是让访问者来自另一个页面的网站上,这将链接到包含滑块的页面点击“幻灯片B”,然后显示幻灯片B.

Perhaps something like some sort of hash tag or anchor in the link like this could trigger something in the Javascript on the page containing the content slider to make Slide B appear: 也许诸如此类的哈希标签或链接之类的锚可能会触发包含内容滑块的页面上的Javascript中的某些内容,从而使幻灯片B出现:

<a href='slidepage.php#slide2>Slide B</a>

The content slider script I'm using is incredibly simple & small, so I'm assuming there's something basic I could add to the script that would recognize a click through to pull a slide: 我正在使用的内容滑块脚本非常简单且很小,因此我假设我可以在脚本中添加一些基本内容,以识别单击以拖动幻灯片的方式:

$(document).ready(function (){
$('#button a').click(function(){
    var integer = $(this).attr('rel');
    $('#myslide .cover').animate({left:-160*(parseInt(integer)-1)})  /*----- Width of div mystuff (here 160) ------ */
    $('#button a').each(function(){
    $(this).removeClass('active');
        if($(this).hasClass('button'+integer)){
            $(this).addClass('active')}
    });
});    

}); });

Again, see the JSFiddle in action here - feel free to fork and help a guy out! 同样,请在此处查看JSFiddle的实际操作 -随意分叉并帮助一个家伙!

Thanks in advance... Chris 预先感谢...克里斯

$(document).ready(function (){
  ...
  your old code
  ...

  if(window.location.hash) {
    // Fragment exists
    var myhash = window.location.hash.substring(1);
    $("a[rel='" + myhash + "']").click();
  }
});

Then use fragments to link to a slide: http://yourhost.com/path/to/page.html#2 然后使用片段链接到幻灯片:http: http://yourhost.com/path/to/page.html#2

Update: Removed # from fragment before using it in the selector. 更新:从片段中删除# ,然后在选择器中使用它。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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