Question

We're trying to hide the 'See More' button once we've loaded all the images from Tumblr, We are using jSon and jQuery and looking for a little help.

We'd love anyone to point us in the right direction and help us out a little as we're currently going around in circles.

<!doctype html>
<html class="no-js" lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width">
<link rel="stylesheet" href="css/style.css">
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js"></script>
<script>window.jQuery || document.write('<script src="js/jquery-1.7.1.min.js"><\/script>')</script>
<script src="js/jquery.masonry.min.js"></script>
<script src="js/modernizr-2.5.3.min.js"></script>
<script type="text/javascript">         
    var offset = 0;
    function load() {
        $.getJSON("http://username.tumblr.com/api/read/json?num=20&start="+offset+"&callback=?",
        function(data) {  
            $.each(data.posts, function(i,item){
                switch(item.type) {
                    case 'photo':
                        $('#content').append('<div class="item"><img src="'+this['photo-url-500']+'" class="stream-image" alt=""/></div>');
                    break;
                }
            });
            $('#content').masonry({
                columnWidth: 320,
                itemSelector: '.item',
                isFitWidth: true,
                isAnimated: !Modernizr.csstransitions
            }).imagesLoaded(function() {
                $(this).masonry('reload');
            });
        });
        offset+=20; 
    }
    $(document).ready(function(){
        load();
        $('.more a').on( "click", function(e) {
            load(); 
            e.preventDefault();
        });

    });
</script>       
</head>
<body>
    <div id="content" class="container clearfix">
    </div> 
    <div class="more">
        <a href="#" title="See More">See More</a>
    </div> 
</body>
</html>
Était-ce utile?

La solution

Before you display the posts check to see if data.posts length is 0. If it is hide the button.

function(data) {  
   if (data.posts.length==0)
      $('.more a').hide();
   else
      $.each(data.posts, function(i,item){
      //rest of your code
Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top