gpt4 book ai didi

javascript - 如何为幻灯片中的每个图像添加链接?

转载 作者:行者123 更新时间:2023-12-01 01:52:30 26 4
gpt4 key购买 nike

我使用了“为什么这张幻灯片闪烁?”中的代码。彼得在网站上给出了您的答案之一,它工作得很好,没有任何闪烁,但我的问题是如何为每个图像添加超链接。我把代码贴出来供大家引用

脚本

(function() {     
// ------
// ###### Edit these.
// Assumes you have images in path named 1.jpg, 2.jpg etc.
var imagePath = "images";
var lastImage = 5;
// How many images do you have?
var fadeTime = 4000;
// var index=1;
// Time between image fadeouts.
// ------
// ###### Don't edit beyond this point.
// No need for outer index var
function slideShow(index) {
var url = imagePath + "/" + index + ".jpg";
// Add new image behind current image
$("#slideShow").prepend($("<img/>").attr("src",url));
// Fade the current image, then in the call back
// remove the image and call the next image
$("#slideShow img:last").fadeOut("slow", function() {
$(this).remove();
setTimeout(function() {
slideShow((index % lastImage) + 1)
}, fadeTime);

});
}
$(document).ready(function() {
// Img 1 is already showing, so we call 2
setTimeout(function() { slideShow(2)}, fadeTime);
delay(1000);
}); })();

</script>

请帮忙......

最佳答案

在此之后:

$("#slideShow").prepend($("<img/>").attr("src",url));

尝试添加这个

$('#slideshow img').wrap('<a href="location" />');

您需要将位置更改为您想要链接所在的位置

关于javascript - 如何为幻灯片中的每个图像添加链接?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5679853/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com