Challenges with JQuery content sliders

I need some guidance in web development as I am new to it. My goal is to create a basic slider using JQuery, but I encountered an issue with slide3. It remains visible while moving across the screen when transitioning to left:0. I'm unsure of what went wrong and would appreciate any insights!

var slide1 = "#slide1";
var slide2 = "#slide2";
var slide3 = "#slide3";

function slideAnimation(moveOut, moveIn, delay1, delay2) {
  setTimeout(function() {
    $(moveOut).animate({
      left: '-100%'
    }, 2000);
    $(moveIn).animate({
      left: '0'
    }, 2000);
  }, delay1);
  setTimeout(function() {
    $(moveOut).hide();
    $(moveOut).animate({
      left: '100%'
    });
    $(moveOut).show();
  }, delay2);
};

function contentSlider() {
  slideAnimation(slide1, slide2, 5000, 5200);
  slideAnimation(slide2, slide3, 10000, 10200);
  slideAnimation(slide3, slide1, 15000, 15200);
};

$(document).ready(function() {
  contentSlider();
});

setInterval(function() {
  contentSlider();
}, 25000);
.index3 {
  height: 482px;
  width: 100%;
  position: relative;
}
#contentSlider {
  position: absolute;
  width: 100%;
  min-height: 482px;
  overflow: hidden;
}
.slideArea {
  position: absolute;
  width: 300%;
  left: -100%;
  height: 100%;
  line-height: 400px;
  font-size: 50px;
  text-align: center;
  left: 0;
}
#slide1 {
  background: url(Images/slide1bkg.jpg) center;
  height: 100%;
  width: 100%;
  position: absolute;
  display: block;
  left: 0;
}
#slide2 {
  background: url(Images/slide2bkg.jpg) center;
  height: 100%;
  width: 100%;
  position: absolute;
  display: block;
  left: 100%;
}
#slide3 {
  background: url(Images/slide3bkg.jpg) left;
  height: 100%;
  width: 100%;
  position: absolute;
  display: block;
  left: 100%;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<section class="index3">
  <div id="contentSlider">
    <!-- slide one content -->
    <div id="slide1" class="slideArea">
      <h5>Slide 1</h5>
    </div>
    <!-- slide two content -->
    <div id="slide2" class="slideArea">
      <h5>Slide 2</h5>
    </div>
    <!-- slide three content -->
    <div id="slide3" class="slideArea">
      <h5>Slide 3</h5>
    </div>
  </div>
  <!-- link to javascript for content slider -->
  <script src="slideshow.js" type="text/javascript"></script>
</section>

If you have any suggestions or solutions, please feel free to share them. Thank you!

Best regards!

Answer №1

Make sure to call the hide() function once the animation that slides -100% left is complete.

function animateSlide(moveOut, moveIn, delay1, delay2) {
    setTimeout(function () {
        $(moveOut).animate({left: '-100%'}, 2000, function(){ 
            $(moveOut).hide();
        });
        $(moveIn).show();       
        $(moveIn).animate({left: '0'}, 2000);
    }, delay1);
    setTimeout(function () {
        $(moveOut).animate({left: '100%'});
    }, delay2);
};

Check out the Fiddle : https://jsfiddle.net/Abc12DeF/ghijk345/

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

Persuading on the Server-Side

After reading through the Google-Caja wiki, I became intrigued by its capabilities. From what I understand, with Caja we can send a snippet of HTML (such as a ) to Google-Caja's server (cajoling service) for processing. The HTML is cajoled and the Jav ...

Tips for making an AJAX request using jQuery

I have a new project that involves collecting user data and displaying it on the same page. I was able to successfully implement an Ajax call using JavaScript, but now I want to transition to using jQuery. Below is my JavaScript code: var output1 = docum ...

How can I ensure security measures are in place to avoid XSS attacks on user-generated HTML content?

Currently, I am in the process of developing a web application that will allow users to upload entire web pages onto my platform. My initial thought was to utilize HTML Purifier from http://htmlpurifier.org/, but I am hesitant because this tool alters the ...

The size of the website elements needs to be increased for better visibility on mobile devices

While developing the official website for my Discord bot - Idle Baker, I opted to utilize Bootstrap 5 for its user-friendly design features, making it easier than dealing with extensive CSS coding. After completing the homepage of the site, I encountered ...

Array of Ascending Progress Indicators

I currently have a progress bar that I'm happy with, but I want to enhance it by incorporating stacked progress bars. My aim is to have the progress bar behave in the following way when an option is selected: https://i.stack.imgur.com/Pw9AH.png & ...

Attempting to incorporate icons into a Material UI table design

Hello, I've incorporated a Material UI table into one of my projects with a design concept similar to this - https://i.stack.imgur.com/i6Fsj.png I'm aiming to include icons within the tables. Here's the code I've worked on so far - ...

The logo image dynamically switches as the user scrolls through various colored sections

Looking to create a feature that changes the logo image as users scroll through different colored sections. Specifically, switching between dark and light themes. a) How can we determine if the section the user is currently on has a dark or light theme? b ...

Creating dynamic JSON objects in Node.js Want to learn how to construct JSON

How can I create a dynamic json object and make a post call? I have tried using ${data.list.name} to retrieve a value from an object, but it doesn't seem to be working. Any suggestions on how to accomplish this? function sendMessageToTeams (data) { ...

Issue with Bootstrap 4 progress bar malfunctioning in popover due to CSS property restrictions within the popover container

The following code functions correctly in the body area: <div class="progress" style="height: 25px;"> <div class="progress-bar" style="width: 30%;" role="progressbar" aria-valuenow="30" aria-valuemin="0" aria-valuemax="100"> </div> & ...

Exploring the functionality of the JavaScript Date constructor in relation to

Will using new Date('2015-01-01') provide me with the exact moment equivalent to 2015-01-01T00:00:00Z? ...

How come the button is shifting down even though it's set to display inline?

I've recently delved into the world of Bootstrap and CSS, but I'm facing a unique challenge. Despite my research efforts, I couldn't find a solution to my specific issue. I have a <div class="col-md-6"> where I've nested ...

Can you modify a specific column in a table using mat-table in Angular material?

For my project, I am utilizing Angular Material's table to present data in a tabular format. However, due to a new requirement, I now need to enable in-line editing for the last 2 columns alongside highlighting another column when the user clicks on t ...

When I close all of my tabs or the browser, I aim to clear the local storage

Could you recommend any strategies for clearing local storage upon closing the last tab or browser? I have attempted to use local storage and session storage to keep track of open and closed sessions in an array stored in local storage. However, this meth ...

Retrieving attributes by their names using dots in HTML

Currently working on an Angular 2 website, I am faced with the challenge of displaying data from an object retrieved from the backend. The structure of the object is as follows: { version: 3.0.0, gauges:{ jvm.memory.total.used:{ value: 3546546 }}} The is ...

The AJAX request is now being "canceled" since the website is up and running

After successfully running AJAX requests on my new version, which was in a sub directory of my site (www.staging.easyuniv.com), I moved the site to the main directory to make it live (www.easyzag.com). Although everything seems to be functioning properly, ...

Conceal Backup Image for Computer Viewing

I am currently working on a project for this website and have added an mp4 video as the background. However, I have run into an issue where the video does not play on mobile devices, so I have had to implement a Fallback Image. The problem is that upon l ...

Finding the exact location of a specific element within a div: tips and tricks

Is there a way to determine the position of an image inside a div when clicked? Here is my HTML code: <div> <p>test</p> <img src='test1.jpg'/> <p>test</p> <p>test</p> <img src=&ap ...

Is it possible to apply draggable functionality in the same way you attach events to an arbitrary node and a selector?

Here is a possible solution: function myFunction(){/*.....*/} $("body").on("click", "li.itemlist", function(){ alert("ping"); }); This code sets up a click event for all li.itemlist elements under the body element. However, is there a way to sim ...

The JQuery function has not been defined within the scripts file

It seems like my jquery function is suddenly undefined and I can't figure out why. I made sure to call jquery before the scripts file, so that's not the issue. Strangely, the jquery was functioning properly until I placed it inside this specific ...

How can I access the id_lang variable in React JS from outside its scope?

How do I access the 'id_lang' variable outside of the render function in order to pass it down for checking? const Navbar = () => { const getID = async (id) => { let id_lang = id; console.log(id_lang); } ret ...