2012-12-31 83 views
0

所以我相當新的JavaScript。我想添加一個鏈接到這個幻燈片中的每個圖像。只有兩個圖像。我試圖把它們鏈接起來,就像你在html中使用<a>一樣......但是這不起作用,因爲它是Javascript。是否有一段簡單的代碼可以將Javascript幻燈片中的每個圖像鏈接到不同的網站?非常感謝。任何反饋都非常感謝。如何鏈接Javascript幻燈片中的單個圖像?

這是我的代碼。由於從dynamicdrive.com

var mygallery=new fadeSlideShow({ 
    wrapperid: "fadeshow1", //ID of blank DIV on page to house Slideshow 
    dimensions: [1024, 511], //width/height of gallery in pixels. Should reflect dimensions of largest image 
    imagearray: [ 
     ["../Images/slideshow_wakeup.png"], 
     ["../Images/slideshow_2.png"] 
     <!--["newappvantagemobile.com/images/slideshow_3.png"]--> 
     //<--no trailing comma after very last image element! 
    ], 
    displaymode: {type:'auto', pause:4500, cycles:0, wraparound:false}, 
    persist: false, //remember last viewed slide and recall within same session? 
    fadeduration: 900, //transition duration (milliseconds) 
    descreveal: "ondemand", 
    togglerid: "" 
}) 
+0

我沒有看到您發佈的代碼有任何問題。也許我沒有明白你的觀點。 –

+0

幻燈片放映效果非常好。但是,我如何添加超鏈接到圖像?例如[「..Images/slideshow_wakeup.png」],我可以在旁邊添加一些東西,以便鏈接。例如,他們會點擊圖片,並將它們帶到google.com –

+0

fadeSlideShow()會做什麼?它是你自己的功能還是別人的代碼? – hayavuk

回答

1

幫助從imagearray陣列的original documentation

["path_to_image", "optional_url", "optional_linktarget", "optional_description"] 

所以,你需要的imagearray陣列改成這樣:

imagearray: [ 
     ["../Images/slideshow_wakeup.png"], "../Images/slideshow_wakeup.png", "_new", "Some text to describe the image."], 
     ["../Images/slideshow_2.png", "../Images/slideshow_2.png", "_new", "Some text to describe the image."], 
     <!--["newappvantagemobile.com/images/slideshow_3.png"]--> 
     //<--no trailing comma after very last image element! 
    ], 

我會解釋一下。該數組有4個元素。

  1. 第一個是圖像的地址(如你所知)。
  2. 第二個是你點擊圖片時會打開的鏈接。
  3. 第三個指定鏈接將如何打開。 _new表示在新窗口/標籤上
  4. 最後一個參數是將在圖像底部顯示的文本。

希望這會有所幫助。

+0

非常感謝。所以這與我想要的方式非常接近。我把這個[「../Images/slideshow_wakeup.png」,「www.google.com」),它看起來很棒,除了它似乎在尋找圖片文件夾中的鏈接或者其他東西。 mywebsite.com/www.google.com,所以它實際上並不鏈接到網站?我如何使它直接進入google.com? –

+0

@MaryAnderson只需將絕對URL放在那裏。含義:'http:// www .google.com'而不是'www.google.com' –

+0

嗨,我有一個問題....如果您嘗試在SlideShow的一個圖像中進行映射,我的意思是設置usemap屬性。可以這樣做嗎?謝謝.. – ssierral