Issues with jQuery slider's fadeIn and fadeOut functionalities are causing unexpected behavior

A question surfaced when implementing a jQuery slider with the help of another user on this website. The issue arose when transitioning the code from the working fiddle to my computer, resulting in a problem that needs addressing. Here is the original fiddle:

http://jsfiddle.net/CWkQE/14/

The code structure is quite straightforward - images are hidden using a 'hide' class and then faded in/out during transitions.

$("active image").fadeIn();
$("to hide image").fadeOut();
$("to hide image").fadeOut();
$("to hide image").fadeOut();

However, an issue has arisen which needs attention.

(Note: GIFs may take time to load, if not visible, here's the direct link:

This sped-up GIF highlights the problem where clicking a button causes the current image to disappear, followed by a slight delay before the next image loads. I attempted to use .delay() but encountered no success.

Answer №1

html

<div id="cycler" style="position:fixed;top:0;">
        <img class="active" src="http://www.gettyimages.com/CMS/StaticContent/1357941082241_new_banner-700x465.jpg" alt="Hoverfly on a green leaf" title="Hoverfly on a green leaf" width="506" height="337" />
        <img src="http://www.royaltyfreeimages.net/wp-content/uploads/2010/09/royalty-free-images-mushroom-500x375.jpg" alt="Fly on a pink flower" title="Fly on a pink flower" width="506" height="337"  />
        <img src="http://www.menucool.com/slider/prod/image-slider-1.jpg" alt="Insect on a leaf" title="Platycheirus granditarsus (I think) on a leaf" width="506" height="337"  />

    </div>
    <div style="margin-top:350px;">
    <button onclick="cycleImages(1)">1</button>
    <button onclick="cycleImages(2)">2</button>
    <button onclick="cycleImages(3)">3</button>
</div>

css

#cycler{position:relative;}
#cycler img{position:absolute;z-index:1;background-color:white}
#cycler img.active{z-index:3}

script

function cycleImages(n){
      var $active = $('#cycler .active');
      var $next = $('#cycler img:nth-child('+n+')');
      $next.css('z-index',2);
      $active.fadeOut(1500,function(){
          $active.css('z-index',1).show().removeClass('active');
          $next.css('z-index',3).addClass('active');
      });
    }

fiddle http://jsfiddle.net/vishnurajv/7wPbd/

If you need a dynamic slideshow, I recommend checking out flexslider

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

Creating a collision mechanism that functions with rotation

I am facing an issue with block collisions in my game. When I rotate the block, collision detection still treats it as a static box. I want to create hit boxes that are rotated along with the block, but I'm unsure of how to achieve this. Additionally ...

Retaining the position of jQuery tabs upon page refresh

I'm facing an issue with my page that contains multiple GridViews within tabs. The problem arises when the page reloads, resetting the tab back to the first one. Below is a snippet of the HTML code: <div id="tabbed_box_1" class="tabbed_box"> ...

Exploring potential methods for generating a PDF invoice in PHP and CodeIgniter by utilizing HTML elements

Greetings everyone, I have encountered a common question on stackoverflow. I am currently working on an HTML invoice template similar to the one showcased in this demo page. My goal is to create a PDF file of the invoice when users click on a specific butt ...

Substitute form input loading

Question: <input id="id_sf-0-use_incident_energy_guess" name="sf-0-use_incident_energy_guess" onchange="show_hide_guess(this.id);" onload="show_hide_guess(this.id);" type="checkbox"> The issue lies with the onload event not working in input fie ...

Just starting out with json/ajax and I received an error in the Console that says: Uncaught TypeError: Cannot read property 'length' of undefined

I’m encountering an issue with my code. I must emphasize that I’m brand new to this, so please bear with me if the solution is simple. I did attempt to solve it myself before reaching out for help and searched through various posts with similar errors, ...

Tips for rearranging the icon placement of the parent menu item on Bootstrap Navigation Bar for mobile display

I need assistance with adjusting the position of the bootstrap navigation menu bar parent menu icon, in mobile view. Currently, the menu header displays a right-arrow-down icon at the end of the header name as shown below. https://i.sstatic.net/kv4T2.png ...

Aligning the Bootstrap 5 Accordion Button in the Center and Adding Line Breaks

I have a few queries regarding the code I am implementing using Bootstrap 5. JSFiddle How can I center align the header within the button? <button class="accordion-button collapsed text-center" type="button" data-bs-toggle=" ...

Tips on changing tabs by simply clicking the save button or linking the save button to tab-switching functionality

import { Component, OnInit, OnDestroy } from '@angular/core'; import { FormGroup, FormControl, Validators, FormArray } from '@angular/forms'; import { CustomValidators } from 'ng2-validation'; import { Busi ...

I aim to retrieve the value of the input textbox located alongside the button using jQuery

Can you help me figure out how to retrieve the value from an input box that is next to a button? Here is the HTML code: <span> <input type="text" value="{{p.filename}}" id="file_{{p.id}}" size=60 onclick="copy_for_file_name({{p.id}}) ...

Finding the index of a selected option in node.js can be achieved using express

I am trying to retrieve the index of the selected object using Express and log it in app.js example.html <form id="tableForm" action="getJson"> <select class="example" name="example"> <option name="table1" value="1"& ...

Using AngularJS to add an element to an array based on a specified condition

dashboardCtrl Data app.controller('dashboardCtrl', ['$scope','$rootScope', function ($scope, $rootScope) { //Color $scope.Color = [{ colorname: "Red", number: "(3)" }, { colorname: "Brown ...

Having trouble interpreting JSON data sent back from a JQuery ajax request

Using JQuery ajax, I am calling a method as shown below $.post('../User/GetCountry', { zone: 1 }, function (data) { alert(data); alert(data["Countries"]); }, "json").fail(functi ...

Looking to conceal content on the navbar background using Bootstrap

From the image above, it is apparent that the text is appearing behind the navigation bar. I'm seeking guidance on how to conceal this text from the navbar when scrolling up the content. Should I create a custom CSS class with properties, or is there ...

Leverage jquery to adjust the height or width of an element depending on which dimension is larger

I'm a beginner in jquery and html and am currently developing a gallery webpage. The functionality involves setting the selected image as the page background and then scrolling vertically based on the mouse pointer's position. This works well for ...

Why is my md-button in Angular Material displaying as full-width?

Just a quick question, I created a simple page to experiment with Angular Material. On medium-sized devices, there is a button that toggles the side navigation, but for some reason, it expands to full width. There's no CSS or Material directives causi ...

Leverage jQuery to organize and categorize JSON information received through an Ajax call

I have retrieved the following array from a MySQL database using PDO: [{ "tbl":"1", "orid":"915", "date":"2021-12-30 12:46:48", "flag":0 }, { "tbl":"2", "orid":"914", "date":"2021-12-30 12:46:21", "flag ...

jQuery refusing to delete class

var profession = "Chiropractor"; var elementsToToggle = "."+profession+"Toggle"; console.log(elementsToToggle); search(elementsToToggle).hide().show(); returns: .ChiropractorToggle TypeError: Object #<error> has no method 'hide' Even th ...

Creating the x and y coordinates for drawImage in HTML5

Understanding the x and y axis has posed a challenge for me: //retrieve last known x and y coordinates ...code var p = $("#draggable"); var offset = p.offset(); var x = offset.left; var y = offset.top; //establish new font siz ...

How can you choose an element by referencing data within one of its child elements?

If I have these two divs: <div class="foo"><div class="bar" data-stuff="1"></div></div> <div class="foo"><div class="bar" data-stuff="2"></div></div> How can I target the div with the class foo when provide ...

Execute Code After Function Completion OR DIV Shows Up

I've created a custom Userscript for Facebook that groups similar notifications together. Surprisingly, it works flawlessly when tested with old notifications on a static HTML page. However, there is an issue: The default DIV container for notificati ...