2011-04-15 85 views
3

我使用了「爲什麼這個幻燈片閃爍?」代碼。哪些彼得已經給你的答案在網站上,它的工作完全正常,沒有任何閃爍,但我的問題是如何添加超鏈接到每個圖像。 我已經粘貼代碼,供大家參考如何添加鏈接到幻燈片中的每個圖像?

腳本

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

請幫助.................

回答

0

在此之後:

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

嘗試添加該

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

您將需要改變位置到您想要的鏈接去的

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')"); 
+0

DalexL謝謝回答我,你有上面給出的代碼將所有的圖像鏈接到同一「www.google.com」,但我需要不同的鏈接爲每個圖像。 – 2011-04-15 17:08:34

+0

你知道這種語言有多少?難道你不能使用某種簡單的if語句或從文件中讀取數據來確定鏈接嗎?我的例子只是例子。爲什麼把每個人都發送到谷歌:P(這是一個很棒的網站,雖然:3) – FreeSnow 2011-04-15 19:56:44

+0

我嘗試插入你之前說過的線路並沒有解決問題。該圖像沒有顯示任何鏈接。 – 2011-04-15 20:26:49

0

代替

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

嘗試使用

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

HTH

相關問題