0

我正在创建一个 jquery 移动应用程序;这是在它正在加载的 div 中加载 flickr 照片缩略图的脚本,但它出现在一个组缩略图中而不是加载每个图像。可以通过编辑这个来加载每个缩略图。我刚刚删除了我的 api 密钥和我的身份证。

$(function() {
var api_key             = 'API KEY';
var user_id             = 'ID';
var photoset_id         = 'PHOTO SET ID';   

var large_image_size    = 'Medium';

var photoset_id,photo_id;
var current = -1;
var continueNavigation = false;


var photos_service      = 'http://api.flickr.com/services/rest/?&method=flickr.photosets.getPhotos' + '&api_key=' + api_key;
var photos_url          = photos_service + '&photoset_id=' + photoset_id + '&media=photos&format=json&jsoncallback=?';

var large_photo_service = 'http://api.flickr.com/services/rest/?&method=flickr.photos.getSizes' + '&api_key=' + api_key;

var $photosContainer    = $('#images').find('#ba');
var $photopreview       = $('#flickr_photopreview');
var $flickrOverlay      = $('#flickr_overlay');
var $loadingStatus      = $('.loading_small');  


$(function(){
    $('#images').stop().animate(200,function(){
        if($photosContainer.is(':empty')){
            /*
            if sets not loaded, load them
            */
            LoadPhotos();
        }
    });
},function(){

}); 



function LoadPhotos(){
    $photosContainer.empty();
    $loadingStatus.css('visibility','visible');

    $.getJSON(photos_url,function(data){
        if(data.stat != 'fail') {
            var photo_count = data.photoset.photo.length;
            var photo_count_total = photo_count ;

            for(var i = 0; i < photo_count; ++i){   
                var photo           = data.photoset.photo[i];
                var photoid         = photo.id;

                var secret          = photo.secret;
                var server          = photo.server;
                var farm            = photo.farm;

                var photoUrl        = 'http://farm'+farm+'.static.flickr.com/'+server+'/'+photoid+'_'+secret+'_s.jpg';

                var $elem           = $('<div />');
                var $link           = $('<a class="toLoad" href="#" />');

                $link.data({
                    'photoid'       :photoid,
                    'secret'        :secret,
                    'server'        :server,
                    'farm'          :farm,
                    'photoUrl'      :photoUrl,
                    'photo_title'   :photo.title
                });
                $photosContainer.append($elem.append($link));

                $link.bind('click',function(e){
                    var $this   = $(this);
                    current     = $this.parent().index();
                    photo_id    = $this.data('photoid');
                    LoadLargePhoto();
                    e.preventDefault();
                });
            }
            LoadPhotosImages();
        }

    });
}



function LoadPhotosImages(){
    var toLoad          = $('.toLoad:in-viewport').size();
    if(toLoad > 0)
        $loadingStatus.css('visibility','visible');
    var images_loaded   = 0;

    $('.toLoad:in-viewport').each(function(i){
        var $space          = $photosContainer.find('.toLoad:first');
        var $img            = $('<img style="display:none;" />').load(function(){
            ++images_loaded;
            if(images_loaded == toLoad){
                $loadingStatus.css('visibility','hidden');
                $photosContainer.find('img').fadeIn();

            }   
        }).error(function(){
            //TODO
            ++images_loaded;
            if(images_loaded == toLoad){
                $loadingStatus.css('visibility','hidden');
                $photosContainer.find('img').fadeIn();

            }               
        }).attr('src',$space.data('photoUrl'))
          .attr('alt',$space.data('photoid'));

        var $photo_title    = $('<span/>',{'html':$space.data('photo_title')});
        $space.append($photo_title).append($img).removeClass('toLoad');
    });
}
4

1 回答 1

0
<!DOCTYPE html>
<html lang="en">
<head>
<script src="js/jquery-latest.js"></script>
<script type="text/javascript">

function downloadImg() {
    $.getJSON("http://api.flickr.com/services/feeds/photos_public.gne?jsoncallback=?",
        {
            ids : "78368944@N06",
            tags: "",
            tagmode: "any",
            format: "json",
        },

        function(data) {
            $('.img-1').attr('src', data.items[0].media.m);
            $('.tit-1').text(data.items[0].title);

            $('.img-2').attr('src', data.items[1].media.m);
            $('.tit-2').text(data.items[1].title);
        }
    );
}

$(document).ready(function() {
        downloadImg();
});
</script>
</head>
<body>
<div class="img-cont"><img class="img-1" /> </div>
<h3 class="tit-1"></h3>

<div class="img-cont"><img class="img-1" /> </div>
<h3 class="tit-1"></h3>

</body>
</html>
于 2012-05-29T16:28:17.197 回答