Present a single image on a personalized HTML slideshow slide

Can anyone help me figure out how to display one image at a time in my slideshow? Right now, all the selected images are showing simultaneously and I'd like them to appear one by one with previous/next buttons. It seems like a simple issue that I might be complicating. I've looked at many examples but my situation is unique because the slideshow content varies each time based on user-selected input. As a result, the next or previous slides will always be different depending on the topics chosen by the user.

If you have any suggestions, please let me know. Here is my current code:

$(document).ready(function() {
  $("#view-content").on("click", function(e) {
    for (var i = 0; i < 20; i++) {
      if ($('#topic' + i).prop('checked')) {
        $('.topic' + i).show();
      } else {
        $('.topic' + i).hide();
      }
    }
  });
});
.column {
  float: left;
  width: 33.33%;
}

.row:after {
  content: "";
  display: table;
  clear: both;
}

input[type=checkbox] {}

.topic {
  width: 200px;
  height: 3em;
  line-height: 3em;
  background: #ccc;
  border-radius: 50px;
  text-align: center;
  vertical-align: middle;
}

button {
  border-radius: 50px;
  border: none;
  width: 10em;
  height: 3em;
  line-height: 3em;
}

.view {
  display: block;
  margin: 0 auto;
}

.selectall {
  display: none;
}

.slideshow {
  overflow: auto;
  white-space: nowrap;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js"></script>
<h1>Topics</h1>

<h4>Or choose from popular search terms: </h4>
<div class="row">
  <button type="button">term1</button>
  <button type="button">term2</button>
  <button type="button">term3</button>
  <button type="button">term4</button>
  <button type="button">term5</button>
  <button type="button">term6</button>
  <button type="button">term7</button>
  <button type="button">term8</button>
  <button type="button">term9</button>
  <button type="button">term10</button>
</div>

<hr>
<div class="row">
  <div class="column">
    <div class="topic">
      <input type="checkbox" id="topic1" />
      <label for="topic1">Topic 1</label>
    </div>
    <br/>
    <div class="topic">
      <input type="checkbox" id="topic2" />
      <label for="topic2">Topic 2</label>
    </div>
    <br/>
    ...
    [remaining lines omitted for brevity]
    
</div>

Answer №1

When it comes to creating a slideshow, the basic structure remains constant even if only select images are displayed. The key difference lies in using display: none for certain images.

To customize your slideshow, you may consider incorporating navigation arrows for users to navigate through images. This can be achieved by implementing pseudo-classes like :before:-first-of-type and :after:last-of-type.

Alternatively, adding a bit of JavaScript or jQuery can enhance functionality:

$(".slideshow > img:gt(0)").hide();

setInterval(function() {
  $('.slideshow > img:first')
    .fadeOut(1000)
    .next()
    .fadeIn(1000)
    .end()
    .appendTo('.slideshow');
}, 3000);

This script hides all images initially and then fades them in sequentially. You can see this in action below:

$(document).ready(function() {
  $("#view-content").on("click", function(e) {
    for (var i = 0; i < 20; i++) {
      if ($('#topic' + i).prop('checked')) {
        $('.topic' + i).show();
      } else {
        $('.topic' + i).hide();
      }
    }
    
    $(".slideshow > img:gt(0)").hide();

    setInterval(function() {
      $('.slideshow > img:first')
        .fadeOut(1000)
        .next()
        .fadeIn(1000)
        .end()
        .appendTo('.slideshow');
    }, 3000);
  });
});
.column {
  float: left;
  width: 33.33%;
}

.row:after {
  content: "";
  display: table;
  clear: both;
}

input[type=checkbox] {}

.topic {
  width: 200px;
  height: 3em;
  line-height: 3em;
  background: #ccc;
  border-radius: 50px;
  text-align: center;
  vertical-align: middle;
}

button {
  border-radius: 50px;
  border: none;
  width: 10em;
  height: 3em;
  line-height: 3em;
}

.view {
  display: block;
  margin: 0 auto;
}

.selectall {
  display: none;
}

.slideshow {
  overflow: auto;
  white-space: nowrap;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js"></script>
<h1>Topics</h1>

<h4>Or choose from popular search terms: </h4>
<div class="row">
  <button type="button">term1</button>
  <button type="button">term2</button>
  <button type="button">term3</button>
  <button type="button">term4</button>
  <button type="button">term5</button>
  <button type="button">term6</button>
  <button type="button">term7</button>
  <button type="button">term8</button>
  <button type="button">term9</button>
  <button type="button">term10</button>
</div>

<hr>
<div class="row">
  <div class="column">
    <div class="topic">
      <input type="checkbox" id="topic1" />
      <label for="topic1">Topic 1</label>
    </div>
    <br/>
    <div class="topic">
      <input type="checkbox" id="topic2" />
      <label for="topic2">Topic 2</label>
    </div>
    <br/>
    <div class="topic">
      <input type="checkbox" id="topic3" />
      <label for="topic3">Topic 3</label>
    </div>
    <br/>
    <div class="topic">
      <input type="checkbox" id="topic4" />
      <label for="topic4">Topic 4</label>
    </div>
    <br/>
    <div class="topic">
      <input type="checkbox" id="topic5" />
      <label for="topic5">Topic 5</label>
    </div>
  </div>
  <div class="column">
    <div class="topic">
      <input type="checkbox" id="topic6" />
      <label for="topic6">Topic 6</label>
    </div>
    <br/>
    <div class="topic">
      <input type="checkbox" id="topic7" />
      <label for="topic7">Topic 7</label>
    </div>
    <br/>
    <div class="topic">
      <input type="checkbox" id="topic8" />
      <label for="topic8">Topic 8</label>
    </div>
    <br/>
    <div class="topic">
      <input type="checkbox" id="topic9" />
      <label for="topic9">Topic 9</label>
    </div>
    <br/>
    <div class="topic">
      <input type="checkbox" id="topic10" />
      <label for="topic10">Topic 10</label>
    </div>
  </div>
  <div class="column">
    <div class="topic">
      <input type="checkbox" id="topic11" />
      <label for="topic11">Topic 11</label>
    </div>
    <br/>
    <div class="topic">
      <input type="checkbox" id="topic12" />
      <label for="topic12">Topic 12</label>
    </div>
    <br/>
    <div class="topic">
      <input type="checkbox" id="topic13" />
      <label for="topic13">Topic 13</label>
    </div>
    <br/>
    <div class="topic">
      <input type="checkbox" id="topic14" />
      <label for="topic14">Topic 14</label>
    </div>
    <br/>
    <div class="topic">
      <input type="checkbox" id="topic15" />
      <label for="topic15">Topic 15</label>
    </div>
  </div>
</div>
<br/>
<button type="button" class="view" id="view-content">View Content</button>
<div class="slideshow">
  <img class="topic1 selectall" src="https://i.imgur.com/Kf2zBCB.jpg" />
  <img class="topic2 selectall" src="https://i.imgur.com/Sd44gRr.jpg" />
  <img class="topic3 selectall" src="https://i.imgur.com/5t6Qp5y.jpg" />
  <img class="topic4 selectall" src="https://i.imgur.com/5vyPC7P.jpg" />
  <img class="topic5 selectall" src="https://i.imgur.com/H400nzy.jpg" />
  <img class="topic6 selectall" src="https://i.imgur.com/MXVqtDe.jpg" />
  <img class="topic7 selectall" src="https://i.imgur.com/OtjnTqO.jpg" />
  <img class="topic8 selectall" src="https://i.imgur.com/OtjnTqO.jpg" />
  <img class="topic9 selectall" src="https://i.imgur.com/OtjnTqO.jpg" />
  <img class="topic10 selectall" src="https://i.imgur.com/OtjnTqO.jpg" />
  <img class="topic11 selectall" src="https://i.imgur.com/OtjnTqO.jpg" />
  <img class="topic12 selectall" src="https://i.imgur.com/OtjnTqO.jpg" />
  <img class="topic13 selectall" src="https://i.imgur.com/OtjnTqO.jpg" />
  <img class="topic14 selectall" src="https://i.imgur.com/OtjnTqO.jpg" />
  <img class="topic15 selectall" src="https://i.imgur.com/OtjnTqO.jpg" />
</div>

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Is there a way for ResponsiveSlides to fade the pager without causing any disruption to the content below, all

I have been working with the Responsive Slides jQuery plugin and made some custom modifications. Everything is going smoothly, but I am facing an issue with getting the pager and next/prev controls to fade in when hovering over the container. Although I s ...

Encountering an ElementClickInterceptedException while trying to click the button on the following website: https://health.usnews.com/doctors

I am currently in the process of extracting href data from doctors' profiles on the website . To achieve this, my code employs Selenium to create a web server that accesses the website and retrieves the URLs, handling the heavy lifting for web scrapin ...

Adjust the height of a sibling div using JavaScript with mouseover event

I need assistance with creating an audio visualizer effect where on mouseover, "this" div becomes the tallest one and the other divs adjust their heights accordingly. How can I specify the specific height for each sister div to change to? Code window ...

Align the drop-down caret to the right using Bootstrap 4.1

I am currently using Bootstrap 4.1 and I have a Navbar that triggers a Modal Dialog Box with tabs and a drop down menu containing an image icon. My goal is to make the "caret" or down arrow of the drop down menu appear on the right side of the image. To a ...

The table refuses to load

I've been troubleshooting this issue for the past two days. The array is visible in the console, but it refuses to show up on the table. I've tried multiple approaches, but none seem to work. I suspect that "tobodyHtml" is not defined properly, a ...

"Unable to get the 'sticky' position to function correctly in tailwindcss

I've been experimenting with Tailwind CSS and trying to implement two sticky elements - a sticky header and a sticky sidebar. My sticky header seems to be working perfectly: <body> <header class="sticky z-50 top-0 hidden"> < ...

Guide on incorporating HTML data into an existing webpage

Requesting assistance in creating an HTML page that features a dynamic drop-down menu. The drop-down should trigger a list to appear upon selection, which can be sourced from either a text file or plain HTML document. The envisioned functionality involves ...

What could be causing my Ajax request with dataType set to "jsonp" to encounter errors?

My code includes an Ajax call that looks like this: var baseurl = Office.context.mailbox.restUrl; var getMessageUrl = baseurl + "/v2.0/me/messages/" + rest_id + "?$select=SingleValueExtendedProperties&$expand=SingleValueExtendedPropertie ...

Traversing distinct JSON data in Handlebars JS

I encountered an issue while attempting to iterate through my JSON object. My approach seemed logical, but for some reason it is not functioning as expected. Here is the most recent attempt I made to solve this problem. <script type="text/x-handlebars ...

Learn the process of effortlessly transferring user information to a MongoDB database

Using socket.io, I am broadcasting geolocation data (lat, lng) and updating the marker icon on a map every time a user connects to the app. When a user from Japan connects, their position is shared with me and vice versa. The issue arises when I only want ...

Sorry, an error occurred while loading the audiosprite - Cannot locate module: 'child_process'

Currently, I am attempting to integrate audiosprite into my React application running on a Webpack server. However, encountering the following error: Error: Module 'child_process' not found in C:\Users\BenLi\Desktop\devel ...

Show text without using alert or textarea upon clicking

I have a JSON ID for a servlet reference, and within this JSON ID, there is a message that I need to display on the webpage. While it currently works with a textarea tag and alert, I want to present the message in a more stylish and animated way. How can I ...

What is the best method for initializing a JavaScript array in my specific scenario?

I had the idea to structure an object similar to this: var collection = [{ 'title': 'title1', 'content': { 'subtitle': 'sub1', 'contents': 'sub content 1' } ...

css - Tips for reducing the speed of inertia/momentum scrolling on mobile devices

I have been working on creating a scrollable card gallery using a CSS grid layout. The structure I am following is similar to this: <div class="gallery-wrapper"> <div class="gallery-container"> <div id="card-1" class="gallery-ca ...

Heroku - JavaScript and CSS Updates Causing Loading Issues

Ruby version: 2.1.5 | Rails version: 4.1.1 For some reason, the changes I make to my JavaScript and CSS files are not reflecting on Heroku; it seems like the cached assets are still being used. I've tried removing the assets and precompiling them bef ...

Discovering the method to retrieve a previous month's date within a VueJs application using Javascript

Can someone guide me on how to retrieve the date of the past month using Vue? This is the code I currently have: import SomeTable from "./table/SomeTable"; export default { name: "Cabinets", components: {SomeTable}, data() { return { ...

Displaying the Ionic loading spinner on the entire page rather than a restricted small box

Right now, I'm able to implement a basic loading effect, but it appears as a small box. presentCustomLoading() { let loading = this.loadingCtrl.create({ content: 'Loading Please Wait...' }); loading.present(); } However, I ...

Creating Component Variants for Google Optimize A/B testing in Next.js

I've been attempting to create a component variant in Google Optimize beyond just text or color changes, but I haven't found a suitable method to do so yet. I'm looking for guidance on how to integrate/configure Optimize with my code in orde ...

How to continuously submit a single form field with Jquery using setInterval?

After reviewing this jquery timer on jsfiddle, I must say it works quite effectively. However, my specific requirement is to submit a single form field at regular intervals. Consider the following HTML form structure: <form id="form"> <input ...

Animating divs one by one using CSS3 with delays

I am experimenting with animating three separate divs one by one, each moving down 50px as a test. Here is the SCSS code I am using: .action { margin: 20px 0; text-align: center; transform: translate(0,0); transition: ...