how to create image gallery with next/previous buttons?











up vote
-1
down vote

favorite












I made a image gallery and added next/previous buttons to this gallery. When click on the image, The gallery is open.So, I tried combine it with other galleries but nothing worked properly. How can I implement below code. This is working (Plunker)






$(document).ready(function(){
$.ajax({
type:"GET",
url:"data.xml",
dataType:"xml",
success:xmlParser2
});
});
function xmlParser2(xml){
xml = $(xml).children();
let i = 0;
let total = $(xml).children().length;
$(xml).children().each(function (idx,index,item) {

let tag = $(this).prop("tagName");
let nextIdx = idx + 1;
let prevIdx = idx - 1;
//to make cyclic
nextIdx = nextIdx == total ? 0 : nextIdx;
prevIdx = prevIdx == -1 ? (total -1) : prevIdx;

let image = '<img style="background-image:url(' + $(this).find("image").text() + ')"' + '" />';
let image2 = '<div><img src="' + $(this).find("image").text() + '" width="100%" alt="' + '" />' + '</div>';
let head = '<div>' + $(this).find("head").text() + '</div>';

let html = `<div class="col-sm-4 random reveal" id="random">
<div class="thumbnail randomdiv3">
<a href="#${tag + idx}" id="openModalBtn">
<div>${image}</div>
<h5>${head}</h5>
</a>
</div>
</div>`;
let popup = `<div id="${tag + idx}" class="overlay">
<div class="popup">

<a href="#${tag + prevIdx}" class="previous round">‹</a>
<a href="#${tag + nextIdx}" class="next round">›</a>
<h6>${head}</h6>
<a class="close" href="#">&times;</a>
<div>${image2}</div>
</div>
</div>`;

$("#xmldata").append(html);

$("#popup").append(popup);
});
}












share|improve this question


























    up vote
    -1
    down vote

    favorite












    I made a image gallery and added next/previous buttons to this gallery. When click on the image, The gallery is open.So, I tried combine it with other galleries but nothing worked properly. How can I implement below code. This is working (Plunker)






    $(document).ready(function(){
    $.ajax({
    type:"GET",
    url:"data.xml",
    dataType:"xml",
    success:xmlParser2
    });
    });
    function xmlParser2(xml){
    xml = $(xml).children();
    let i = 0;
    let total = $(xml).children().length;
    $(xml).children().each(function (idx,index,item) {

    let tag = $(this).prop("tagName");
    let nextIdx = idx + 1;
    let prevIdx = idx - 1;
    //to make cyclic
    nextIdx = nextIdx == total ? 0 : nextIdx;
    prevIdx = prevIdx == -1 ? (total -1) : prevIdx;

    let image = '<img style="background-image:url(' + $(this).find("image").text() + ')"' + '" />';
    let image2 = '<div><img src="' + $(this).find("image").text() + '" width="100%" alt="' + '" />' + '</div>';
    let head = '<div>' + $(this).find("head").text() + '</div>';

    let html = `<div class="col-sm-4 random reveal" id="random">
    <div class="thumbnail randomdiv3">
    <a href="#${tag + idx}" id="openModalBtn">
    <div>${image}</div>
    <h5>${head}</h5>
    </a>
    </div>
    </div>`;
    let popup = `<div id="${tag + idx}" class="overlay">
    <div class="popup">

    <a href="#${tag + prevIdx}" class="previous round">‹</a>
    <a href="#${tag + nextIdx}" class="next round">›</a>
    <h6>${head}</h6>
    <a class="close" href="#">&times;</a>
    <div>${image2}</div>
    </div>
    </div>`;

    $("#xmldata").append(html);

    $("#popup").append(popup);
    });
    }












    share|improve this question
























      up vote
      -1
      down vote

      favorite









      up vote
      -1
      down vote

      favorite











      I made a image gallery and added next/previous buttons to this gallery. When click on the image, The gallery is open.So, I tried combine it with other galleries but nothing worked properly. How can I implement below code. This is working (Plunker)






      $(document).ready(function(){
      $.ajax({
      type:"GET",
      url:"data.xml",
      dataType:"xml",
      success:xmlParser2
      });
      });
      function xmlParser2(xml){
      xml = $(xml).children();
      let i = 0;
      let total = $(xml).children().length;
      $(xml).children().each(function (idx,index,item) {

      let tag = $(this).prop("tagName");
      let nextIdx = idx + 1;
      let prevIdx = idx - 1;
      //to make cyclic
      nextIdx = nextIdx == total ? 0 : nextIdx;
      prevIdx = prevIdx == -1 ? (total -1) : prevIdx;

      let image = '<img style="background-image:url(' + $(this).find("image").text() + ')"' + '" />';
      let image2 = '<div><img src="' + $(this).find("image").text() + '" width="100%" alt="' + '" />' + '</div>';
      let head = '<div>' + $(this).find("head").text() + '</div>';

      let html = `<div class="col-sm-4 random reveal" id="random">
      <div class="thumbnail randomdiv3">
      <a href="#${tag + idx}" id="openModalBtn">
      <div>${image}</div>
      <h5>${head}</h5>
      </a>
      </div>
      </div>`;
      let popup = `<div id="${tag + idx}" class="overlay">
      <div class="popup">

      <a href="#${tag + prevIdx}" class="previous round">‹</a>
      <a href="#${tag + nextIdx}" class="next round">›</a>
      <h6>${head}</h6>
      <a class="close" href="#">&times;</a>
      <div>${image2}</div>
      </div>
      </div>`;

      $("#xmldata").append(html);

      $("#popup").append(popup);
      });
      }












      share|improve this question













      I made a image gallery and added next/previous buttons to this gallery. When click on the image, The gallery is open.So, I tried combine it with other galleries but nothing worked properly. How can I implement below code. This is working (Plunker)






      $(document).ready(function(){
      $.ajax({
      type:"GET",
      url:"data.xml",
      dataType:"xml",
      success:xmlParser2
      });
      });
      function xmlParser2(xml){
      xml = $(xml).children();
      let i = 0;
      let total = $(xml).children().length;
      $(xml).children().each(function (idx,index,item) {

      let tag = $(this).prop("tagName");
      let nextIdx = idx + 1;
      let prevIdx = idx - 1;
      //to make cyclic
      nextIdx = nextIdx == total ? 0 : nextIdx;
      prevIdx = prevIdx == -1 ? (total -1) : prevIdx;

      let image = '<img style="background-image:url(' + $(this).find("image").text() + ')"' + '" />';
      let image2 = '<div><img src="' + $(this).find("image").text() + '" width="100%" alt="' + '" />' + '</div>';
      let head = '<div>' + $(this).find("head").text() + '</div>';

      let html = `<div class="col-sm-4 random reveal" id="random">
      <div class="thumbnail randomdiv3">
      <a href="#${tag + idx}" id="openModalBtn">
      <div>${image}</div>
      <h5>${head}</h5>
      </a>
      </div>
      </div>`;
      let popup = `<div id="${tag + idx}" class="overlay">
      <div class="popup">

      <a href="#${tag + prevIdx}" class="previous round">‹</a>
      <a href="#${tag + nextIdx}" class="next round">›</a>
      <h6>${head}</h6>
      <a class="close" href="#">&times;</a>
      <div>${image2}</div>
      </div>
      </div>`;

      $("#xmldata").append(html);

      $("#popup").append(popup);
      });
      }








      $(document).ready(function(){
      $.ajax({
      type:"GET",
      url:"data.xml",
      dataType:"xml",
      success:xmlParser2
      });
      });
      function xmlParser2(xml){
      xml = $(xml).children();
      let i = 0;
      let total = $(xml).children().length;
      $(xml).children().each(function (idx,index,item) {

      let tag = $(this).prop("tagName");
      let nextIdx = idx + 1;
      let prevIdx = idx - 1;
      //to make cyclic
      nextIdx = nextIdx == total ? 0 : nextIdx;
      prevIdx = prevIdx == -1 ? (total -1) : prevIdx;

      let image = '<img style="background-image:url(' + $(this).find("image").text() + ')"' + '" />';
      let image2 = '<div><img src="' + $(this).find("image").text() + '" width="100%" alt="' + '" />' + '</div>';
      let head = '<div>' + $(this).find("head").text() + '</div>';

      let html = `<div class="col-sm-4 random reveal" id="random">
      <div class="thumbnail randomdiv3">
      <a href="#${tag + idx}" id="openModalBtn">
      <div>${image}</div>
      <h5>${head}</h5>
      </a>
      </div>
      </div>`;
      let popup = `<div id="${tag + idx}" class="overlay">
      <div class="popup">

      <a href="#${tag + prevIdx}" class="previous round">‹</a>
      <a href="#${tag + nextIdx}" class="next round">›</a>
      <h6>${head}</h6>
      <a class="close" href="#">&times;</a>
      <div>${image2}</div>
      </div>
      </div>`;

      $("#xmldata").append(html);

      $("#popup").append(popup);
      });
      }





      $(document).ready(function(){
      $.ajax({
      type:"GET",
      url:"data.xml",
      dataType:"xml",
      success:xmlParser2
      });
      });
      function xmlParser2(xml){
      xml = $(xml).children();
      let i = 0;
      let total = $(xml).children().length;
      $(xml).children().each(function (idx,index,item) {

      let tag = $(this).prop("tagName");
      let nextIdx = idx + 1;
      let prevIdx = idx - 1;
      //to make cyclic
      nextIdx = nextIdx == total ? 0 : nextIdx;
      prevIdx = prevIdx == -1 ? (total -1) : prevIdx;

      let image = '<img style="background-image:url(' + $(this).find("image").text() + ')"' + '" />';
      let image2 = '<div><img src="' + $(this).find("image").text() + '" width="100%" alt="' + '" />' + '</div>';
      let head = '<div>' + $(this).find("head").text() + '</div>';

      let html = `<div class="col-sm-4 random reveal" id="random">
      <div class="thumbnail randomdiv3">
      <a href="#${tag + idx}" id="openModalBtn">
      <div>${image}</div>
      <h5>${head}</h5>
      </a>
      </div>
      </div>`;
      let popup = `<div id="${tag + idx}" class="overlay">
      <div class="popup">

      <a href="#${tag + prevIdx}" class="previous round">‹</a>
      <a href="#${tag + nextIdx}" class="next round">›</a>
      <h6>${head}</h6>
      <a class="close" href="#">&times;</a>
      <div>${image2}</div>
      </div>
      </div>`;

      $("#xmldata").append(html);

      $("#popup").append(popup);
      });
      }






      javascript jquery html xml






      share|improve this question













      share|improve this question











      share|improve this question




      share|improve this question










      asked Nov 9 at 11:02









      Saji

      166




      166





























          active

          oldest

          votes











          Your Answer






          StackExchange.ifUsing("editor", function () {
          StackExchange.using("externalEditor", function () {
          StackExchange.using("snippets", function () {
          StackExchange.snippets.init();
          });
          });
          }, "code-snippets");

          StackExchange.ready(function() {
          var channelOptions = {
          tags: "".split(" "),
          id: "1"
          };
          initTagRenderer("".split(" "), "".split(" "), channelOptions);

          StackExchange.using("externalEditor", function() {
          // Have to fire editor after snippets, if snippets enabled
          if (StackExchange.settings.snippets.snippetsEnabled) {
          StackExchange.using("snippets", function() {
          createEditor();
          });
          }
          else {
          createEditor();
          }
          });

          function createEditor() {
          StackExchange.prepareEditor({
          heartbeatType: 'answer',
          convertImagesToLinks: true,
          noModals: true,
          showLowRepImageUploadWarning: true,
          reputationToPostImages: 10,
          bindNavPrevention: true,
          postfix: "",
          imageUploader: {
          brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
          contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
          allowUrls: true
          },
          onDemand: true,
          discardSelector: ".discard-answer"
          ,immediatelyShowMarkdownHelp:true
          });


          }
          });














          draft saved

          draft discarded


















          StackExchange.ready(
          function () {
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53224489%2fhow-to-create-image-gallery-with-next-previous-buttons%23new-answer', 'question_page');
          }
          );

          Post as a guest















          Required, but never shown






























          active

          oldest

          votes













          active

          oldest

          votes









          active

          oldest

          votes






          active

          oldest

          votes
















          draft saved

          draft discarded




















































          Thanks for contributing an answer to Stack Overflow!


          • Please be sure to answer the question. Provide details and share your research!

          But avoid



          • Asking for help, clarification, or responding to other answers.

          • Making statements based on opinion; back them up with references or personal experience.


          To learn more, see our tips on writing great answers.





          Some of your past answers have not been well-received, and you're in danger of being blocked from answering.


          Please pay close attention to the following guidance:


          • Please be sure to answer the question. Provide details and share your research!

          But avoid



          • Asking for help, clarification, or responding to other answers.

          • Making statements based on opinion; back them up with references or personal experience.


          To learn more, see our tips on writing great answers.




          draft saved


          draft discarded














          StackExchange.ready(
          function () {
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53224489%2fhow-to-create-image-gallery-with-next-previous-buttons%23new-answer', 'question_page');
          }
          );

          Post as a guest















          Required, but never shown





















































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown

































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown







          這個網誌中的熱門文章

          Academy of Television Arts & Sciences

          L'Équipe

          1995 France bombings