如何在幻灯片中添加链接到每个图像?

时间:2011-04-15 16:44:08

标签: javascript jquery

我使用了“为什么这个幻灯片闪烁?”中的代码。彼得在网站上给出了你的一个答案,它完美无缺,没有任何闪烁,但我的问题是如何为每个图像添加超链接。 我已粘贴代码供您参考

脚本

(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>

请帮助.................

3 个答案:

答案 0 :(得分:0)

在这里:

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

(我真的不知道JQuery或者这是什么,我确实理解Javascript + HTML,但是)

你可以添加一个:

.attr("onClick",JAVASCRIPTNAMEHERE)

到最后?

$("#slideShow").prepend($("<img/>").attr("src",url).attr("onClick","window.Navigate('www.Google.com')"); 

答案 1 :(得分:0)

之后:

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

尝试添加此

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

您需要将位置更改为您希望链接转到的位置

答案 2 :(得分:0)

而不是

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

尝试使用

$("#slideShow").prepend($("<a href='" + url + "'><img src='" + url + "' /></a>"));  

HTH