1

这是流行的 jquery-plugin Galleria的主页。我需要在活动图像的右下角插入下载链接。现在有可用的统计数据,如 (3/10),它表示列表中的当前数字。也许有人已经这样做了。最快的方法是什么?


UPD:使用gearsdigital的想法,我编写了代码:

var gallery = Galleria.get(0);

gallery.bind(Galleria.IMAGE, function(e) {
    imgHandle = e.imageTarget;
    console.log(imgHandle);
    console.log(imgHandle.attr('href'));
    //$('.galleria-counter').append('<a href="'+imgHandle.attr('src')+'">Download</a>');
});

第一个日志行显示如下:

<img width="584" height="438" src="http://....jpg" style="display: block; position: relative; left: 0px; top: -4px; opacity: 1;">

但是如何获取 src 位置,我看到attr函数不可用的错误。

4

2 回答 2

2

imgHandle从 aDOMEvent而不是 jquery 对象中获取。

作为attrjQuery 对象的一部分,您需要将 dom 对象传输到 jquery 对象。

gallery.bind(Galleria.IMAGE, function(e) {
    imgHandle = $(e.imageTarget); //Wrap it here

   alert(imghandle.attr('href'))

    //$('.galleria-counter').append('<a href="'+imgHandle.attr('src')+'">Download</a>');
});
于 2010-09-19T11:49:02.170 回答
1

我会尝试从当前图像中获取当前的 Source-Attribute 并将其附加为链接。

//Untested. This is just a suggestion :)
currentImageSource = $('.galleria-image img').attr('src');  
$('.galleria-counter').append('<a href="'+currentImageSource+'">Download</a>');

但是像这样的链接会单独打开图像而不是普通下载。如果你想要一个“真正的”下载,你必须把这个图像放在一个 zip 存档中。

$('.galleria-counter').append('<a href="'+currentImageSource+'.zip">Download</a>');

这将产生类似的东西:http://www.example.com/galleria/img/mygreatimage.jpg.zip

为我工作:

<!DOCTYPE html>
<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
        <title>Example</title>
        <script type="text/javascript" src="http://code.jquery.com/jquery-1.4.2.min.js"></script>

        <script type="text/javascript">
            $(document).ready(function() {

                currentImageSource = $('.container img').attr('src');  
                $('.placeholder').append('<a href="'+currentImageSource+'">Download</a>');

            });

        </script>
    </head>

    <body>
        <div class="container">
            <h2>Get img src</h2>
            <img src="http://www.duba.at/wp-content/uploads/2007/08/bild_0570000.jpg" witdh="200" height="220"/>
        </div>

        <div class="placeholder">
            <h2>Append Here</h2>
        </div>

    </body>
</html>
于 2010-09-19T08:23:33.670 回答