如何使jquery图库视图可点击?

时间:2013-05-15 08:55:48

标签: jquery

我正在使用此http://spaceforaname.com/galleryview/

我需要为每张图片插入链接,所以我添加了如下所示的链接,但它不起作用。无论如何我可以点击图像跳到某个地方吗?

<ul id="myGallery">
 <li><a href="#"><img src="http://www.spaceforaname.com/galleryview/img/photos/bp1.jpg" alt="Lone Tree Yellowstone" /></a>
 <li><a href="#"><img src="http://www.spaceforaname.com/galleryview/img/photos/bp1.jpg" alt="Lone Tree Yellowstone" /></a>
</ul>

2 个答案:

答案 0 :(得分:1)

您必须修改Galleryview的.js:

  1. 在jquery.galleryview-3.0-dev.js第22行下方插入以下行:

    this.customlink = img.attr('customlink');
    this.haslink = img.attr('haslink');

  2. 接下来,在第467行下方,插入以下行:

    var address = "'" + gvImage.customlink + "'";
    var js = "window.location.assign(" + address + ");";
    if(gvImage.haslink=='true') {img.attr("onclick", js);}

  3. 触发Galleryview的HTML代码现在如下:

    <ul id="myGallery">
    <li><img haslink="true" customlink="somelink" src="images/1.jpg" alt="Lone Tree Yellowstone" />
    <li><img haslink="true" customlink="somelink" src="images/2.jpg" alt="Lone Tree Yellowstone" />
    </ul>

  4. 如果您想将图库的图像视为链接,请设置“haslink=true”。 “customlink”属性的使用方式与“href”属性的使用方式相同。 您也可以使用uldiv包围,并将其设为“cursor:hand;cursor:pointer;” 所以用户意识到图像是一个链接。

    希望这有帮助!

答案 1 :(得分:0)

试试这个:

$('img').click(function(){
window.location.href = "http://stackoverflow.com";
});