imagecube js多维数据集旋转错误



我对imagecube jquery插件有一个小问题。http://keith-wood.name/imageCube.html

我已经让它在主页上运行得很好,有三张未链接的图片。当我在它们周围放置链接时,向上旋转会变得不稳定。有人有什么想法吗?提前谢谢。链接如下:

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

您可以将onclick属性与window.location.href=">insert url here<"一起用于每个带有css cursor: pointer;的图像,而不是包装anker标记:

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;
}

另请参见此示例。

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="...">属性,因此页面可能无法在大多数验证器中进行验证。

最新更新