简体   繁体   English

如何链接到幻灯片中的图像?

[英]How do I make a link to an image in a slideshow?

For my portfolio website I made a slideshow with cycle2 carousel with some big images on my work page. 在我的投资组合网站上,我用cycle2传送带进行了幻灯片演示,并在工作页面上放了一些大图像。

All images are also displayed on the homepage really small. 所有图像也显示在首页上很小。

I would like to make the smaller images on the homepage function as links to the bigger images within the slideshow. 我想在首页功能上制作较小的图像,作为指向幻灯片内较大图像的链接。

I tried to give all images in the slideshow a different id to link to. 我试图给幻灯片中的所有图像提供不同的ID以便链接。 But the link always goes to the first image of the slideshow and not the image with the id. 但是,链接始终转到幻灯片的第一张图片,而不是指向id的图片。 Can anyone maybe give me some advice on this? 有人可以给我一些建议吗?

Thank you, Noa 谢谢,诺亚

You'll need to utilize the cycle2 api to transition the slideshow to the appropriate slide when the user clicks the link. 当用户单击链接时,您需要利用cycle2 api将幻灯片显示转换为适当的幻灯片。 Here's the relative snippet from the api documents: 以下是api文档的相对代码段:

// goto 3rd slide
$('.cycle-slideshow').cycle('goto', 2);

You just have to use the index numbers of the slide in question. 您只需要使用相关幻灯片的索引号即可。 You would run this code then have the link point to the anchor of the slideshow. 您将运行此代码,然后使链接指向幻灯片的锚点。

Rest of the documentation on the api can be found here: http://jquery.malsup.com/cycle2/api/ 可以在以下位置找到有关api的其他文档: http : //jquery.malsup.com/cycle2/api/


UPDATE UPDATE

$(document).ready( function() {
    var field = 'slide';
    var url = window.location.href;
    var slideNumber = url.indexOf('?slide');
    if ( slideNumber === -1 ) {
        slideNumber = url.indexOf('&slide');
    }
    if ( slideNumber >= 0 ) {
        $('.cycle-slideshow').cycle('goto', url[slideNumber + 1]);
    }
});

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

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