JSON - Outputting JSON object

0 votes
97 views
added Aug 2, 2019 in API by LC Marshal Captain (25,770 points)
var nextpostLink = '/content/1568637/back-pain-learn-how-get-rid-it-fitness-fun-and-fruits-galore';

//viewport function
$.fn.thisInViewport = function() {
    var elementTop = $(this).offset().top,
        elementBottom = elementTop + $(this).outerHeight(),
        viewportTop = $(window).scrollTop(),
        viewportBottom = viewportTop + $(window).height();

    return elementBottom > viewportTop && elementTop < viewportBottom;
};
// api data
var apiData = 'http://www.somaku.com/users'; 

$.getJSON(apiData, function (data) {
    $.each(data, function (key, j0) {
    
        // Generate a random post
        function nextPost() {
            var post = '<div id="nexpost" class="news-article>';
            post += '<div class="entry-heading">';
            post += '<div class="website-name">';
            post += `<a href="${j0.website}" rel="category tag">${j0.website_name}</a></div>`;
            post += `<h2 class="username">${j0.username}</h2>`;
            if ($(window).width() > 768) {
                post += '<div class="top2-entry-post-share">';
                post += '</div>';
            }
            else {

            }
            post += '</div>';

            return post;
        }
        if(infEl.length) {
            mainContent.append(nextPost());
            $(window).on('resize scroll', function() {
                if ($('#nexpost').thisInViewport()) {
                    window.history.pushState("", "", nextpostLink);
                } else {
                    // window.location.href;
                }
            });
        }
    });
});

 

lazacode.org - Malaysia's programming knowledge sharing platform, where everyone can share their finding as reference to others.
...