简体   繁体   English

在 div 中显示图像并添加 PREV/NEXT 按钮

[英]Show image in div and add PREV/NEXT buttons

I create kind of gallery in Wordpress.我在 Wordpress 中创建了一种画廊。 However, posts are listed with plugin (they are attached to map - WP Google Map) and I can't use any gallery plugin.但是,帖子与插件一起列出(它们附加到地图 - WP Google Map)并且我不能使用任何图库插件。 I just upload images and want to add them to div "showimagediv".我只是上传图像并想将它们添加到 div“showimagediv”。 This works fine but I can't make PREV/NEXT.这很好用,但我不能制作 PREV/NEXT。

This is what it looks like:这是它的样子:

$(document).ready(function() {
  $('.thumb').on('click', function() {
    var img = $('<img />', {
      src: this.src,
      'class': 'fullImage'
    });
    $('.showimagediv').html(img).show();
  });

  $('.showimagediv').on('click', function() {
    $(this).hide();
  });
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div class="post_content">
  <img src="image1.jpg" class="thumb" />
  <img src="image2.jpg" class="thumb" />
  <img src="image3.jpg" class="thumb" />
</div>
<div class="post_content">
  <img src="image4.jpg" class="thumb" />
  <img src="image5.jpg" class="thumb" />
  <img src="image6.jpg" class="thumb" />
</div>
<div class="post_content">
  <img src="image7.jpg" class="thumb" />
  <img src="image8.jpg" class="thumb" />
  <img src="image9.jpg" class="thumb" />
</div>

It works well but doesn't give me option to to PREV/NEXT.它运行良好,但没有让我选择上一个/下一个。

This is untested - but might help you get the idea.这是未经测试的 - 但可能会帮助您了解这个想法。

HTML HTML

<div class="nextSelector">
    <span>NEXT</span>
</div>

JS JS

$('.nextSelector').on('click',function(){
    var nextImage = $('img.fullImage + img');
    $('img.fullImage').toggleClass("thumb fullImage");
    nextImage.toggleClass("thumb fullImage");
})

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM