The issue of slides overlapping in a Javascript slideshow during auto play mode

I encountered an issue while creating an automatic slideshow with 4 slides. Upon autoplay for the first time, slide 1 overlaps slide 4, as well as slide 2 and 3. This only happens once after the site loads. However, on subsequent playthroughs or when using the navigation dots at the bottom, the slideshow functions perfectly without any problems.

$(document).ready(function(){

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

var slidesl = $('.slideitem').length

var d = "<li class=\"dot active-dot\">&bull;</li>";

for (var i = 1; i < slidesl; i++) {
  d = d+"<li class=\"dot\">&bull;</li>";
}   
var dots = "<ul class=\"slider-dots\">" + d + "</ul\";

$("#slideshow").append(dots);
$("#slideshow > div:gt(0)").hide();
var interval = setInterval(slide, 3000);

function intslide(func) {
    if (func == 'start') { 
    interval = setInterval(slide, 3000);
    } else {
        clearInterval(interval);        
        }
}

function slide() {
        sact('next',0, 1200);
}
    
function sact(a, ix, it) {
        var currentSlide = $('.current');
        var nextSlide = currentSlide.next('.slideitem');
        var prevSlide = currentSlide.prev('.slideitem');
            var reqSlide = $('.slideitem').eq(ix);

            var currentDot = $('.active-dot');
          var nextDot = currentDot.next();
          var prevDot = currentDot.prev();
            var reqDot = $('.dot').eq(ix);
        
        if (nextSlide.length == 0) {
            nextDot = $('.dot').first();
            nextSlide = $('.slideitem').first();
            }

        if (prevSlide.length == 0) {
            prevDot = $('.dot').last();
            prevSlide = $('.slideitem').last();
            }
            
        if (a == 'next') {
            var Slide = nextSlide;
            var Dot = nextDot;
            }
            else if (a == 'prev') {
                var Slide = prevSlide;
                var Dot = prevDot;
                }
                else {
                    var Slide = reqSlide;
                    var Dot = reqDot;
                    }

        currentSlide.fadeOut(it).removeClass('current');
        Slide.fadeIn(it).addClass('current');
        
        currentDot.removeClass('active-dot');
        Dot.addClass('active-dot');
}   


$('.next').on('click', function(){
        intslide('stop');                       
        sact('next', 0, 400);
        intslide('start');                      
    });//next

$('.prev').on('click', function(){
        intslide('stop');                       
        sact('prev', 0, 400);
        intslide('start');                      
    });//prev

$('.dot').on('click', function(){
        intslide('stop');
        var index  = $(this).index();
        sact('dot', index, 400);
        intslide('start');                      
    });//prev
//slideshow
});

View the fiddle link for this code - https://jsfiddle.net/Udara_Samapth/c1zevrLj/23/

Answer №1

After reviewing your slide presentation, I have identified several factors contributing to the overlapping issue. Upon closer examination of your jquery/JS code, I noticed that you are using a combination of the jquery hide method and fadeIn/fadeOut functions within the sact() function, resulting in opacity adjustments.

   currentSlide.fadeOut(it).removeClass('current');
   Slide.fadeIn(it).addClass('current');

This approach causes elements at the top and bottom to blend together at certain opacity levels.

To address this problem, there are two potential solutions that come to mind:

  1. An easy fix would be to add a background color to the affected item.
.slideshow .slideitem {
  display: none;
  background: #FFF;
}
  1. Alternatively, you could adjust the timing of the opacity transitions by adding delays to the fadeIn() and fadeOut() functions within your JS code.

For reference, here is a link to a working example: https://jsfiddle.net/liquidcharcoal/gqyjph1a/13/

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

Using node.js to parse an XML file from a URL and iterate through it to retrieve all the URLs contained within

I am currently utilizing the node module xml2js. The format of my xml file looks like this: <?xml version="1.0" encoding="UTF-8" ?> <?xml-stylesheet type="text/xsl"?> <?xml-stylesheet type="text/css" media="screen" href="some url" ?> ...

- Discover the steps to displaying an ajax response in a stylish fancybox iframe

Currently, I am facing an issue with displaying cart (viewcart.jsp) in an iframe using fancybox when adding a product to the cart. Here is what I have attempted so far. How can I effectively pass the ajax response to the iframe? $(document).ready(functio ...

Converting Node.js Date.toString() output into a time format in Go

My go service is currently receiving data from an external source. Here's how the data appears (in JSON format)- { "firstName": "XYZ", "lastName": "ABC", "createdAtTimestamp": "Mon Nov 21 2 ...

Is there a way to update the styling of specific sections of an input field as the user enters text in React?

Just like in most markdown editors, I am looking to enable the ability to modify parts of an input field as the user enters text. For instance: When the user types "_above_", as soon as the second underscore is typed, the text should be styled accordingly ...

Message toggle not functioning in custom method of jQuery Validate plugin

Here is a custom rule that I have implemented: jQuery.validator.addMethod("onespecial", function(value, element){ var pattern = /^(?=.{6,})(?=.*[a-z])(?=.*[0-9])|(?=.*[!@#$%^&*()-+=]).*$/; return (pattern.test(value)); }, "Your ...

The outline feature cannot be applied to buttons within a btn-group in Bootstrap 4

I have successfully removed the outline for a single button, but I am struggling to remove it for a button within a btn-group class. Check out my JSFiddle DEMO This is the HTML code I am working with: <button class="btn btn-primary">Button without ...

the angular-ui-tinymce directive allows for seamless image uploads using a file browser

Utilizing jQuery, we have the ability to incorporate local images into the tinymce editor similar to what is demonstrated in this jsfiddle, by following the guidelines provided in the documentation. The Angular module for tinymce can be found at angular-u ...

Troubleshooting: Unable to modify value with function in AngularJS

Why can't I change a value using a function in AngularJS? html: <div ng-controler='TestCtrl' id='TestCtrl'> <h1>Test: {{test.name}}</h1> <div ng-hide='showTest'> <div class=&a ...

When we typically scroll down the page, the next section should automatically bring us back to the top of the page

When we scroll down the page, the next section should automatically bring us back to the top of the page without having to use the mouse wheel. .bg1 { background-color: #C5876F; height: 1000px; } .bg2 { background-color: #7882BB; height: 1000px; } .bg3 ...

Is there a way to activate the autoplay feature for this?

I'm really new to Jquery and most of this code isn't mine, I'm just using it as a learning tool for creating sliders. If someone could give me some guidance on how to make this slider work automatically when the page loads, that would be gre ...

Cease the use of bi-directional data binding on an Angular directive

One way I've been attempting to send information to a directive is through the following setup: <ui-message data="{{app}}"></ui-message> In my controller, this is how I define it: app.controller("testCtrl", function($scope) { $scope.a ...

Concealing specific sections of HTML content in a webview on the fly

I've been experimenting with a proof of concept feature to implement the ability to conceal certain parts of a web page loaded in a webview, but I seem to be encountering some issues... Within a UIWebview extension, I have something similar to this c ...

I am looking to sort users based on their chosen names

I have a task where I need to filter users from a list based on the name selected from another field called Select Name. The data associated with the selected name should display only the users related to that data in a field called username. Currently, wh ...

inability to conceal a two-dimensional marker array within Google Maps API v3

I need some help with my marker that refuses to hide Even after using setMap, my marker is still visible on the map Here is the error message from the console Please assist! Thank you in advance markers[i][j].setMap(null); markers.setMap(null); va ...

Is Meteor.js the solution for time-triggered server requests?

We are currently in the process of developing an application that matches users from a database every Wednesday and Friday. How can we achieve this using Meteor? In the server code, I am considering organizing this functionality within a timedserver.js fi ...

Dynamic Bootstrap tooltip

I have a simple Javascript code snippet that I'm struggling with: $("#myinput").hover(function(){ if(condition){ $(this).tooltip({placement: "bottom", title: "mytitle"}); } ); Accompanied by its HTML cou ...

What sets apart responseJSON from $.parseJSON?

Usually, when working with JSON, I gather data in the following way: <?php $some_array = array("success" => "The upload is successful", "failed" => "The upload has failed"); echo json_encode($some_array); ?> <script type="text ...

Is it a bad idea to incorporate JavaScript functions into AngularJS directives?

I came across this snippet of code while working with ng-repeat: <div ng-show="parameter == 'MyTESTtext'">{{parameter}}</div> Here, parameter represents a string variable in the $scope... I started exploring if it was possible to c ...

javascript implementing optional chaining for a single parameter

Is it possible to implement optional chaining on a single parameter? setAllProperties( Object.values(users).flatMap(({ properties }) => Object.values(properties) ) ); I am looking for a way to ensure that the properties folder exists in ...

Compass - substitute a single value for an alternate attribute

Can I utilize a value from one class to customize another? Consider the following class: .sourceClass { color: red; } And now, let's say we have this class: .destinationClass { border-color: ###needs to match the color in .sourceClass => re ...