V
V
Vladimir Obabkov2016-11-06 21:10:41
JavaScript
Vladimir Obabkov, 2016-11-06 21:10:41

History API for displaying loaded ajax content?

Hello!
I give the code .. Sobsno it displays albums from the VK group. And on click it displays photos in the masonry grid.
He displays them simply in the block under the albums. Which is inconvenient.
I would very much like to make it so that the pictures were displayed instead of albums.

$(document).ready(function($) {
    $.ajax({
      url: 'https://api.vk.com/method/photos.getAlbums?',
      data: {
        owner_id: '-72629433',
        need_covers: '1',
        photo_sizes: '1'
      },
      dataType: 'jsonp',
      success: function(data) {
        data.response.forEach(function(item) {
        for (i = 0; i < 9; i++) { // длина массива sizes = 9 (всего размеров)
          var typeImg = item.sizes[i].type; // перебираем все type

          if (typeImg == 'r') {
            break; // если находим нужный type, говорим остановить перебор
          }
        }
        var aid = item.aid;
        var thumb = item.sizes[i].src // а тут выводим в переменную после break!
        var title = item.title;
        $('<div><a class="" onclick="albums(this)" href="#grid"><img src="' + thumb + '"/>' + item.aid + '</div>').appendTo('.nav-albs');
      });
      }
    });
  });

  function albums(el) {

    var $container = $('.grid').masonry({
      columnWidth: 400,
      itemSelector: '.grid-item',
      gutter: 5
    });
    $container.masonry('remove', $('.grid-item')).masonry(); // очищаем сетку методом плагина masonry()
    $.ajax({
      url: 'https://api.vk.com/method/photos.get?',
      data: {
        owner_id: '-72629433',
        album_id: el.text, // аргумент ID альбома
          count:30
      },
      dataType: 'jsonp',
      success: function(data) {
        data.response.forEach(function(item) {
          var img = item.src_big;
          !img ? img = item.src_big : img;
          var moreBlocks = '<div class="grid-item"><img src="' + img + '" alt="" class="img-alb"/></div>';
          var $moreBlocks = $(moreBlocks);
              $container.append($moreBlocks);
              $container.masonry('appended', $moreBlocks);
              $container.imagesLoaded().progress(function() {
  $container.masonry('layout'); // после подгрузки фотографий, начинаем упорядочивание >:
});
        });
      }

I would do it myself .. But no matter how I do .. Everything does not work.
Mb who will help?
Well, or poke into something similar

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question