weixin_33719619 2015-07-20 19:21 采纳率: 0%
浏览 26

保持相同的图像

I'm trying to make a jQuery/Ajax gallery, everything works but when i push the "Bekijk" button i always get the same image, the next button also doesn't work. Can someone help me?

(function($){

  $(".fancybox").fancybox();
  function loopGallery(test, index, item){
    if(test){
        var box = $('<div class="col-md-4 box_animaux box-'+index+'"></div>');
        var pola = $('<div class="pola"></div>');
        var view = $('<div class="view thumb"></div>');
        var mask = $('<div class="mask"><h2>'+item.name+'</h2><p>'+item.description+'</p><a href="img/4.jpg" class="info fancybox" rel="group" title="'+item.id+'" ><div class="alt">Bekijk</div></a></div>')

        $('.gallery').prepend(box);
        box.append(pola);
        pola.append(view);
        view.prepend('<img src="'+item.source+'">');
        view.append(mask);
    }
  }

  $.getJSON('json/photos.json', function(data){
    $.each(data, function(index, item){
        loopGallery(index <= 2, index, item);
    });
  });

  $('.next').on('click', function(event){
    event.preventDefault();
    var galleryLength = $('.pola').length;
    $.ajax('json/photos.json', {
        success: function(data){
            $.each(data, function(index, item){
                loopGallery(item.id >= galleryLength && item.id < galleryLength + 3, index, item);
            });
        },
        beforeSend: function(){
            $('.next').hide();
            $('.spinner').fadeIn();
        },
        complete: function(){
            $('.spinner').hide();
            $('.next').fadeIn();
        }
    });
  });
})(jQuery);
  • 写回答

1条回答 默认 最新

  • weixin_33719619 2015-07-20 19:39
    关注

    try to Change

      $('.next').on('click', function(event){
    

    To

      $('body .next').on('click', function(event){
    

    Also for Bekijk, You have static image path so it will keep same image dispay. change this

    <a href="img/4.jpg"
    

    To

     <a href="'+item.source+'"
    
    评论

报告相同问题?

悬赏问题

  • ¥15 ETLCloud 处理json多层级问题
  • ¥15 matlab中使用gurobi时报错
  • ¥15 这个主板怎么能扩出一两个sata口
  • ¥15 不是,这到底错哪儿了😭
  • ¥15 2020长安杯与连接网探
  • ¥15 关于#matlab#的问题:在模糊控制器中选出线路信息,在simulink中根据线路信息生成速度时间目标曲线(初速度为20m/s,15秒后减为0的速度时间图像)我想问线路信息是什么
  • ¥15 banner广告展示设置多少时间不怎么会消耗用户价值
  • ¥15 可见光定位matlab仿真
  • ¥15 arduino 四自由度机械臂
  • ¥15 wordpress 产品图片 GIF 没法显示