2012-02-08 33 views
0

我有一個imagecube jquery插件的小問題。 http://keith-wood.name/imageCube.htmlimagecube js cube旋轉錯誤

我已經得到它在三個UNLINKED圖像的主頁上工作得很好。當我把鏈接放在他們周圍時,向上的旋轉變得詭異。任何人有任何想法?提前致謝。鏈接如下:

http://www.bigideaadv.com/a-z/

+2

tbh,一個簡單的淡入淡出或幻燈片動畫會看起來更好,更平滑。 – grc 2012-02-08 19:56:54

+0

我同意,但這不是客戶想要的。 – 2012-02-08 20:49:18

回答

1

你可以用CSS cursor: pointer;而不是包裝的安克爾標籤使用onclick屬性與window.location.href=">insert url here<"爲每個圖像:

HTML:

<div id="image_carousel2"> 
    <img src="/a-z/./images/slide1_alt.jpg" width="960" height="353" onclick="window.location.href='/a-z/generic';" /> 
    <img src="/a-z/./images/slide2_alt.jpg" width="960" height="353" onclick="window.location.href='/a-z/about-a-and-z';" /> 
    <img src="/a-z/./images/slide3_alt.jpg" width="960" height="353" onclick="window.location.href='/a-z/operations';" /> 
</div> 

CSS:

#image_carousel2 img { 
    cursor: pointer; 
} 

另請參閱this example

+0

不一定是我一直在尋找的答案,但您的解決方案完美無缺。謝謝。 – 2012-02-08 20:50:35

1

Scessor的解決方案可能是您不想去的方式,您也可以在每次輪換時動態地將圖像打包並解包到<a>標籤中。 imageCube的beforeRotate和afterRotate處理程序使這成爲可能。

HTML:

<div id="image_carousel2" style="width: 960px; height:353px; left:-10px; position:relative; margin:0 auto; background:transparent !important;"> 
    <img src="/a-z/./images/slide1_alt.jpg" width="960" height="353" url="http://www.bigideaadv.com/a-z/generic" /> 
    <img src="/a-z/./images/slide2_alt.jpg" width="960" height="353" url="http://www.bigideaadv.com/a-z/about-a-and-z" /> 
    <img src="/a-z/./images/slide3_alt.jpg" width="960" height="353" url="http://www.bigideaadv.com/a-z/operations" /> 
</div> 

的javascript:

$(document).ready(function() { 
    $('#image_carousel2').imagecube({ 
     direction: 'up', 
     expansion: 25, 
     segments: 15, 
     reduction: 30, 
     speed: 1000, 
     pause: 7000, 
     shading: false, 
     //Before rotate, remove wrapping anchor (if it exists) from current img. 
     beforeRotate: function startRotate(current, next) { 
      if(current.parentNode.tagName.toLowerCase() == 'a') {//Safety 
       $(current).unwrap();//Remove the wrapping anchor. 
      } 
     }, 
     //After rotate, wrap next img in its anchor 
     afterRotate: function endRotate(current, next) { 
      var $next = $(next); 
      $next.wrap($next.data('anchor'));//Wrap the next img in its anchor. 
     } 
    }); 
    //Now create an <a> node for each img in the cube, 
    //and save as a .data() property of its <img> node. 
    //This allows reuse of <a> nodes, avoiding the need to 
    //(re)create them dynamically at each rotation. 
    $('#image_carousel2 img').each(function(i){ 
     var $this = $(this); 
     var $a = $('<a>').attr('href', $this.attr('url')); 
     $this.data('anchor', $a); 
     if(i==0){ $this.wrap($a); }//Wrap the first node in its anchor. 
    }); 
}); 

正如你所期望的那樣,HTML被簡化,但JS是更加複雜。

請注意,此解決方案使用自定義<img ... url="...">屬性,因此該頁面可能無法在大多數驗證器中驗證。