JQuery Flickr API

发布于 2024-08-03 09:50:55 字数 1191 浏览 3 评论 0原文

我正在使用 jQuery 和 Flickr REST API 编写脚本。

遵循伪算法

1) 点击 Flickr API 并使用 $.getJSON 获取照片列表,然后创建 li 列表元素:

create_gallery: function(){
    $.getJSON(
        $.prep_api_url(),
        function(data){
            $.each(data.photos.photo, function(i,item){
                var photo_raw_url = 
                    'http://farm' + item.farm + '.static.flickr.com/' + 
                    item.server + '/' + item.id + '_' + item.secret;
                var photo_url = photo_raw_url + '_b.jpg';
                $('<li><a id="' + item.id + '" class="image_trigger" href=' + 
                   photo_url + '><img class="thumbnails" src=' + photo_raw_url +
                       '_s.jpg' + ' width=22 hight=22 /><a/>' +
                       '</li>').appendTo('.image_thumbs');
            });
            $('.thumbnails').css({'opacity' : '.6'});
        }
    );
},

2) 通过引用创建的列表来预加载所有图像(我在这里遇到问题)

3)单击每个图像时都会显示预加载数组中的图像

现在我想要这个

1)从 Flickr 获取 JSON 对象

2)创建列表并将其附加到 DOM

3)成功插入后,遍历列表中的所有图像并按顺序一张一张地预加载它们。

我也尝试过异步选项,但什么也没发生

I am writing a script using jQuery and Flickr REST API.

following the the pseudo algo

1) Hit Flickr API and get a list of photos using $.getJSON nad create li list elements:

create_gallery: function(){
    $.getJSON(
        $.prep_api_url(),
        function(data){
            $.each(data.photos.photo, function(i,item){
                var photo_raw_url = 
                    'http://farm' + item.farm + '.static.flickr.com/' + 
                    item.server + '/' + item.id + '_' + item.secret;
                var photo_url = photo_raw_url + '_b.jpg';
                $('<li><a id="' + item.id + '" class="image_trigger" href=' + 
                   photo_url + '><img class="thumbnails" src=' + photo_raw_url +
                       '_s.jpg' + ' width=22 hight=22 /><a/>' +
                       '</li>').appendTo('.image_thumbs');
            });
            $('.thumbnails').css({'opacity' : '.6'});
        }
    );
},

2) Preload all the images by refferring created list (I have Problems Here)

3) On click of every image display the image from preloaded array

Now I want this

1) get the JSON object from Flickr

2) create the list and append it to DOM

3) after successfull insertion, run through all images from list and preload them sequentially one by one.

I have also tried async option, nothing happend

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

偏爱你一生 2024-08-10 09:50:56

我在 while 循环中使用 JS 图像对象和加载函数来预加载图像,然后再将它们添加到 DOM。

您可以通过查看源代码找到结果: http://www.neerajkumar.name/necromancer/

I used JS image object and load functions in a while loop to preload images before adding them to DOM.

you can find the result by viewing the source code at: http://www.neerajkumar.name/necromancer/

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文