2014-02-28 68 views
0

的事情是http://jsfiddle.net/hTZWq/2/幻燈片鏈接,滑動按鈕

 $(".image").wrap("<a href=\"link.html\"></a>"); 

我想,所以當PIC改變它有鏈接,每個圖片把這些變種的鏈接。 與這些代碼我的按鈕不工作在我的電腦bur在這裏他們的小提琴工作?!奇怪。

它不斷改變我的第一張照片與這些間隔功能。

有人可以幫忙!

回答

0

如何存儲的圖像是這樣的:

var image = [ 
    {src: "pretend this is an image", link: "http://www.google.com"}, 
    {src: "and lets pretend this is another", link: "http://www.yahoo.com"}, 
    {src: "and one more for show", link: "http://www.stackoverflow.com"} 
]; 

然後你就可以改變你的HTML()方法生成的標記時,在image.srcimage.link性能通過。

+0

我是一個初學者,所以有點難以忽略,你在說什麼:/,那部分是「然後你可以改變你的html()方法在生成標記時傳遞image.src和image.link屬性。 「 – Mario

0

你可以試試這個代碼:

HTML

<a href="link1.html" class="picture">pretend this is an image</a> 
<div class="bullet">click here to change manually</div> 

的jQuery:

$(document).ready(function() { 
    setInterval(function() { //change this to setInterval to make it constantly flip through rather than one time 
     change(); 
    }, 2400); 
}); 

var image = [ 
    ["pretend this is an image", "link1.html"], 
    ["and lets pretend this is another", "link2.html"], 
    ["and one more for show", "link3.html"] 
]; 
var index = 1; 

$(".bullet").click(function() { 
    change(); 
}); 

function change() { 
    if (index == 3) { 
     index = 0; 
    } 
    $(".picture").fadeOut(1000, function() { 
     $(".picture").html(image[index][0]); 
     $(".picture").attr("href", image[index][1]); 
     $(".picture").fadeIn(1000); 
     index++; 
    }); 
} 

檢查updated Fiddle

+0

http://jsfiddle.net/y8n3W/我會如何處理這些代碼? – Mario

+0

你試過自​​己什麼? – LinkinTED

+0

我發佈了錯誤的代碼,我使用的代碼是這一個http://jsfiddle.net/y8n3W/,因爲我是新來的,我真的不明白「編碼」呢。 – Mario