Animate your slider with the swipe gesture using jQuery and CSS

UPDATE: I have made modifications to the code and included a more detailed example to clarify my objective.

I successfully created a slider using jQuery. Each element is assigned the class .active, which reveals the hidden elements.

My current goal is to implement a swipe animation, allowing the images to transition from left to right.

The challenge lies in integrating this feature into my existing complex code.

For reference, here is an example of the desired outcome:

Below is the code snippet:

https://codepen.io/Insane415/pen/NggLxe

<div class="slider">
  <div class="row">
    <div class="col-md-4">
      <div class="image-holder">
        <img src="http://via.placeholder.com/350x150" style="display:none;" class="active">
        <img src="http://via.placeholder.com/350x150" style="display:none;">
        <img src="http://via.placeholder.com/350x150" style="display:none;">
        <img src="http://via.placeholder.com/350x150" style="display:none;">
      </div>
      <div class="bullet-points">
        <a href="_self" class="active-bullet">•</a>
        <a href="_self">•</a>
        <a href="_self">•</a>
        <a href="_self">•</a>
      </div>
    </div>
    <div class="col-md-2">
      <div class="thumbnails">
        <img src="http://via.placeholder.com/350x150" class="active-thumbnail">
        <img src="http://via.placeholder.com/350x150">
        <img src="http://via.placeholder.com/350x150">
        <img src="http://via.placeholder.com/350x150">
      </div>
    </div>
    <div class="col-md-6 center-me" style="height:100%;">
      <div class="text-holder">
        <div class="text active">
          <p>Lorem Ipsum</p>
          <h2>Giant Heading 1</h2>
          <p>Just some more text</p>
          <a href="/de/tariffinder" class="button">zur Preisübersicht</a>
        </div>
        <div class="text">
          <p>Lorem Ipsum</p>
          <h2>Giant Heading 2</h2>
          <p>Some more text</p>
          <a href="/de/tariffinder" class="button">zur Preisübersicht</a>
        </div>
        <div class="text">
          <p>Lorem Ipsum</p>
          <h2>Giant Heading 3</h2>
          <p>Some more text</p>
          <a href="/de/tariffinder" class="button">zur Preisübersicht</a>
        </div>
        <div class="text">
          <p>Lorem Ipsum</p>
          <h2>Giant Heading 4</h2>
          <p>Some more text</p>
          <a href="/de/tariffinder" class="button">zur Preisübersicht</a>
        </div>
      </div>
    </div>

  </div>

.text-holder .text p{margin: 0!important;}
.slider{
  padding: 15px;
  margin-top: 50px;
  background: url('/images/content/slider/Banner_Hintergrund_telbes-01.jpg');
  background-repeat: no-repeat!important;
  background-size: cover!important;
  display: inline-block;
  width: 100%;
  border: 1px solid #ddd;
}

.slider .bullet-points a{
    color: #ccc;
}

.thumbnails{

  height: 195.11px;
  margin-left: -25px;
}

.thumbnails img{
  display:block;
  max-height: 31.65%;
  margin-bottom: 5px;
}

.thumbnails img:hover{
  cursor: pointer;
}

.text-holder{
  margin-left: 0px;
  height: 100%;
}

.text-holder .text{
  display: none;
}

/*display active image*/

.active{
  display: block!important;
}

/*hide thumbnail when image is active*/

.active-thumbnail{
  display: none!important;
}

.bullet-points{
  display: block;
  text-align: center;
  margin-top: 15px;
}

.bullet-points a{
  font-size: 40px;
  text-decoration: none;
  color: #ccc;
}

.active-bullet{
  color: #E22C26!important;
}

/*.image-holder{
  max-width: 350px!important;
}

.image-holder img{
  max-width: 350px!important;
}*/

.image-holder img{
  /* text-align: center!important; */
  margin: 0 auto;
}

.bullet-points a:hover{
  color: #E22C26!important;
}

.center-me{
  margin-top: 4%;
}

.text-holder a{
  margin-top: 15px;
    padding: 10px 20px 10px 20px;
}

.text-holder a:hover{
    padding:10px 20px 10px 20px;
}

.text-holder{
  font-size: 130%;
  color: inherit;
}

.text-holder h2{
  font-size: 200%;
}

    $(document).ready(function() {

  var images = [$(".image-holder img:first-child"), $(".image-holder img:nth-of-type(2)"), $(".image-holder img:nth-of-type(3)"), $(".image-holder img:last-child")];
  var thumbnails = [$(".thumbnails img:first-child"), $(".thumbnails img:nth-of-type(2)"), $(".thumbnails img:nth-of-type(3)"), $(".thumbnails img:last-child")];
  var text = [$(".text-holder .text:first-child"), $(".text-holder .text:nth-of-type(2)"), $(".text-holder .text:nth-of-type(3)"), $(".text-holder .text:last-child")];
  var backgrounds = ["url('/images/content/slider/Banner_Hintergrund_telbes-01.jpg')", "url('/images/content/slider/Banner_Hintergrund_telbes-02.jpg')", "url('/images/con... (message truncated)

Answer №1

To achieve this effect, you can utilize CSS3 in the following way:

Assign each image an absolute position along with a specified width and height.

Set the height of the image container to ensure that your slider pager is positioned below the images.

Utilize both @keyframes and transition to showcase how the desired effect can be attained.

In the javascript slider function, there is a function added to facilitate the addition and removal of transitions.

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

Intersecting a line with a sphere in ThreeJS

I am working with a scene that includes a red line and a sphere. As the camera rotates, zooms, or moves, I need to check if the line intersects with the sphere from the current camera position (refer to the images below). To visualize this scenario, pleas ...

Assistance required in forming a Button Group featuring a Pointer Shape

https://i.sstatic.net/bBwqi.png I came up with this idea for a button group. <div class="btngroup"> <button type="button" class="btn">Organization</button> <button type="button" class="btn">Project</button> <butto ...

ReactJS encountered an error: _this3.onDismissID is not defined as a function

My goal is to retrieve the latest news related to a specific search term from a website, showcase them, and provide a dismiss button next to each news item for users to easily remove them if desired. Here's a snippet of the code I'm using: import ...

In HTML, define a trigger that will submit the form when a <p> tag is clicked

What is the alternative way to make an element like <p> trigger form submission without using a button? Any solutions available? <form> <p>I wish for this to submit the form</p> <input type='submit' value=&apo ...

creating links for navigating to previous pages is crucial for enhancing

Take a look at the code snippet provided. The objective here is to display the previous pagination numbers if the "pagestart" input is 5 or greater. Otherwise, only 5 page numbers will be shown. Refer to the attached HTML for a clearer understanding. Thank ...

What is the method for generating a 2D array in JavaScript when the array's length is unknown?

I'm trying to create a 2D array that groups animals by their first letter of the alphabet. However, the output is not what I expected. I want each letter to have its own sub-array with corresponding animal names. Here's the code I tried: functio ...

Guide on creating a mongoose query to search through subdocuments

My Mongoose schema is named "Users" and it includes a subdocument called "Roles" as one of its variables: var UserSchema = new mongoose.Schema({ email: { type: String, required: true, unique: true }, password: { type: String, required: true }, ...

Is there a way to add to a list using the example provided and display the result as well

Here is the given information: data=[{"id":1,"name":"vikash","roll":39},{"id":2,"name":"kumar","roll":3}] data2=[{"hobby":"football","food":&quo ...

Can you tell me how to achieve the functionality of the ".get" statement in JavaScript that is present in python-firebase?

After writing Python code that retrieves the entire JSON database, I attempted to achieve the same functionality in JavaScript without success. Despite its apparent straightforwardness, I have yet to discover a viable solution. var firebase = require(&apo ...

Express encountered a simple web application error

Greetings, this marks my debut post. As a coding novice, I have been following tutorials on opentutorials.org/course/2136/11950 I attempted to troubleshoot errors in my code, but unfortunately I've hit a roadblock. Upon accessing the site, it displa ...

When the jQuery AJAX call is successful, the function is returned as data

Here is my implementation using codeigniter flashdata with a jQuery AJAX call: <script type="application/javascript"> var res_no = '<?php echo $this->session->flashdata('res_no'); ?>'; var res_new = '<?php ec ...

Guide to implementing server-side data loading in App.js using Next.js

Is there a way to fetch the layout data along with the page without adding it to every individual page? The issue I'm facing is that my layout component, loaded once on App.jsx, remains consistent throughout the session. However, due to SSRed page loa ...

Ajax - Every single request has been successfully fulfilled

I am struggling to determine when all my Ajax requests are finished in order to call another function. I have attempted to use various methods with native Ajax functions in Chrome, but none of them seem to be working for me. Can someone please help me? H ...

Accessing Image Inputstream from Servlet with jQuery

I have created a servlet that fetches an image from MySQL and sends it to JSP using jQuery. The servlet retrieves an object from MySQL, converts it to JSON, and then uses jQuery to display the object attributes. When I run the JSP file, I can see the stri ...

Unable to select checkbox within a table using Selenium WebDriver with Java

Having trouble checking a checkbox inside a table using Selenium Webdriver in Java? Even with version 2.52.0 of Selenium, the element not found error persists across different web browsers. The iFrame seems to be correct as I can interact with other compon ...

Utilizing relative URIs in Node.js request library

I've encountered an issue with my code where node.js is unable to resolve the url: const request = require('request') const teamURL = `/users/${user._id}/teams`; const req = request({ url: teamURL, json: true }, function(error, ...

Updating Data with Ajax in Laravel

Hey there, could you walk me through the process of updating with Ajax? I'm working with Laravel I prefer using HTML and Ajax only Here are my routes: Route::post('/post/homepage', 'AdminController@HomePage'); ...

Divs aligned horizontally with automatic height

I am facing a dilemma with two child divs placed side by side within a parent div. The height of each div is generated based on the viewport-size, making it unknown. The issue arises in the left div where an image needs to be resized to match the height o ...

What are the steps to creating a screen that mimics a mirror in the physical world?

Is there a way for the user to see themselves when they open a URL? I'm not looking for a mirror effect like the one produced by jQuery reflection js. I don't want to rely on using the front camera or any other camera to achieve this. Any sugges ...

Error: ws variable is not defined

I've integrated puppeteer into my React project using Webpack and Babel. I've included this simple code in my component, but unfortunately, I encountered an error. async goToPage() { const browser = await puppeteer.launch(); const page ...