Step-by-step guide on how to animate the title for each slide separately

I have successfully created a custom jQuery slideshow that functions as intended. The only remaining task is to animate the caption within each slide. I would like each caption to correspond with its respective slide, but currently all of the captions respond regardless of which slide is displayed. I am struggling to troubleshoot and resolve this issue.

<body>
    <div class="marquee_container">
        <div class="holder">
            <div class="slide">
                <img class="marquee_panel_photo" src="images/photos/london.jpg" alt="London" />
                <div class="marquee_caption">
                    <div class="marquee_caption_content">
                        <p>Content goes here</p>
                    </div>
                </div>
            </div>
            <div class="slide">
                <img class="marquee_panel_photo" src="images/photos/milan.jpg" alt="Milan" />
                <div class="marquee_caption">
                    <div class="marquee_caption_content">
                        <p>Content goes here</p>
                    </div>
                </div>
            </div>
            <div class="slide">
               <img class="marquee_panel_photo" src="images/photos/staugustine.jpg" alt="St Augustine" />
                <div class="marquee_caption">
                    <div class="marquee_caption_content">
                        <p>Content goes here</p>
                    </div>
                </div>
            </div>
        </div>
        <div class="marquee_nav">
        </div>
    </div>
</body>
</html>

CSS

.marquee_container { 
    width: 700px; 
    height: 350px; 
    overflow: hidden; 
    margin: 0px 0px 30px 0px; 
    padding: 0px; 
    position:relative;
}
.holder{
    overflow: hidden;
    position: relative;
    width: 9999px; 
    height: 350px; 
}
.slide{
    width: 700px;
    float: left;
    position:relative;
}
.marquee_photos { 
    overflow:hidden;
}
.marquee_photos img{
    display:block;
}
.marquee_caption {
    width: 700px;
    margin: 0px;
    padding: 15px 0px 10px 0px;
    color: #fff;
    position: absolute;
    top: 350px;
    left: 0px;
    background: url(images/template/marquee_caption.png) 0px 0px;
}
.marquee_caption_content { 
    width: 410px;
    padding: 0px 0px 0px 25px;
}
.marquee_nav{
    position:absolute;
    bottom:5px;
    right:0;    
}
.marquee_nav .marquee_nav_item{
    color:#fff;
    text-decoration:none;
    background:url(images/template/nav_buttons.png) no-repeat;
    text-indent:-9999px;
    overflow:hidden;
    display:block;
    width:17px;
    height:18px;
    float:left;
    margin:0 4px;
}
.marquee_nav .marquee_nav_item:hover{
    background:url(images/template/nav_buttons.png) no-repeat -25px 0;
}
.marquee_nav .marquee_nav_item.selected{
    background:url(images/template/nav_buttons.png) no-repeat -50px 0;
}

JQUERY

$(document).ready(function(){

    //1st STEP
    // Automatically generate navigation links for each slide
    $('.slide').each(function(index, value){
        $('.marquee_nav').append('<a href="#" class="marquee_nav_item"></a>');
    });

    //2nd STEP
    // Set the navigation links and initiate the slideshow
    $('.marquee_nav .marquee_nav_item').on('click', function(){
        $('.marquee_nav_item').removeClass('selected');
        $(this).addClass('selected');

        //3rd STEP
        // Animate the slideshow
        var navClick = $(this).index();
        var holderWidth = $('.marquee_container').width();
        var photoPosition = navClick * holderWidth;

        $('.marquee_container .holder').animate({'margin-left' : -photoPosition}, 1000);

        // Animate the caption
        $('.marquee_caption').animate({'top':275}, 500);
    });
});

Answer ā„–1

If you find that the .marquee_caption elements need to be reset to their original positions before bringing the selected one into view, you can try the following approach:

For example:

...
$('.marquee_caption').not(':eq(' + navClick + ')').animate({ 'top': 200 }, 500);
$('.marquee_caption').eq(navClick).animate({ 'top': 100 }, 500);
...

In this code snippet, navClick represents the variable already present in your code storing the .index() of the chosen navigation element. By passing this value into the .eq() jQuery method, you target the specific element.

Feel free to review a modified jsFiddle showcasing an illustration using your code for simplicity.

I hope this solution aligns with your requirements.

Additional Information:

  • The .eq() method in jQuery uses an index parameter to retrieve just one element from a group.
  • The .not() method excludes elements based on the provided selector rule.
  • In the initial line above, among the 3 .marquee_caption elements, we select all except the currently active one as per the navClick index. This results in selecting 2 out of 3 elements which are then animated accordingly.
  • As a final step, you can conveniently trigger the click event on the respective .marquee_nav_item element by employing the same .eq() method. Add the following just before closing the $(document).ready(...) function:
    $('.marquee_nav .marquee_nav_item').eq(0).trigger('click');
    .
  • This is merely one option and possibly the most direct method. By manually triggering the click event, you initiate subsequent actions outlined in the click function.

Answer ā„–2

//moving the caption with animation
$(this).closest('.slide').find('.marquee_caption').animate({'top':275}, 500);

Does this align with your expectations?

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

Having trouble retrieving the content of a DIV using JavaScript? Can't get .innerHTML to work?

Currently, I am working on a jQuery drag and drop feature and aiming to save the final outcomes in a database. My approach involves utilizing JavaScript to extract values, but I seem to be encountering an issue where 'NULL' is returned instead of ...

Show an image when hovering over a dot using CSS - without hovering directly on the image

I'm currently working on a merchandising page that involves photoshopping several products onto a background image. I want customers to be able to hover over a dot positioned on each product to reveal its information and provide a link similar to . Ho ...

Tips for iterating through an array of objects nested within other objects

Good afternoon everyone, Iā€™m having trouble accessing the attributes of a JavaScript object array through AJAX. Can anyone spot where I might be going wrong? View image description This is my AJAX call: $("#cbx1").on("change", func ...

What is the best method to retrieve the country name from a world map using D3.js?

I'm trying to figure out how to retrieve the country name from a click event on the D3 world map. Despite inspecting the DOM, I can't quite understand how the country's name, code, or population is associated with the map. The template for ...

Steps for opening a link from a jQuery dialog box

I am seeking guidance on how to navigate through a link generated by PHP. Upon clicking the link, a jQuery dialog box should appear, and once the "OK" button is clicked, the code should proceed to follow the PHP-generated link. Below is an excerpt of the ...

Getting data from a response in Express.js involves using the built-in methods provided by

I am a beginner at Node.js and I'm currently experimenting with client-server communication. Below are the codes I've been working on: server: app.post('/zsa', (req, res) => { res.send("zsamo"); }); client: fetch(&qu ...

Regular expression used for removing an HTML tag <object> from a string

I'm working with an HTML string that contains some simple text: <div><object height="315" width="560"></object><div><object height="315" width="560"></object></div></div> Is there a way to eliminate an ...

The LinkedIn API: Creating a Customized User Interface Experience

I'm experimenting with dynamically populating the data-id attribute with a public URL fetched from LinkedIn search results. Assuming I can retrieve the public profile URL, when I use the script directly on the page (not through JavaScript), it works. ...

Exclusively for Numerical Input with Number Keys

A customer on a website requires a Zip Code field that only accepts 5-digit numbers and triggers the numeric keypad on iOS and Android devices. It should also be compatible with external number pads on laptops. I've tried various approaches like keyC ...

What can be done to address the issue of v-model select option onchange displaying the previously selected value or becoming stuck on a static value rather than updating

Whenever I navigate to the message page and select a device, the v-model selected value changes. However, if I go to the device or contact page, the v-model selected value remains unchanged or goes back to the last selected value. Below is the function in ...

Execute the post action and navigate to the page with the help of jQuery

Is there a way to redirect to another page after performing a post action using jQuery? I attempted the following code: $.ajax({ type: "POST", url: response.data.myUrl, data: JSON.stringify(response.data.myPar ...

Error: The device you are trying to access with GetUserMedia is not available

Attempting to access an IP Camera that is connected to a WiFi network. Even though I am connected to the same WiFi, I keep encountering an error. Strangely, I can connect using VLC, but getUserMedia returns null. @Component({ selector: 'app-home&a ...

What is the best way to prevent npm install from running in nested workspace directories?

I've recently started utilizing npm workspaces in my project. Here is the structure of the app: . +-- package.json -- packages +-- a | -- package.json -- b -- package.json The npm install script should ideally be executed from ...

Activate validation when the scope of a custom validator is modified

Consider a scenario where we have a custom validator with an input as the attribute's value. app.directive('inputRequired', function() { return { require: 'ngModel', scope: { inputRequired: '=& ...

Utilizing a combination of Infinite Scroll, Isotope, and Firebase Firestore for seamless pagination functionality

Just starting out in the world of web development. Any help is appreciated! I'm attempting to showcase items stored in Firestore by utilizing paginate queries. The aim is for each time a user reaches the bottom of the page, we trigger a call to Fires ...

Apply a class to an element as it comes into view 100 pixels before scrolling past it

I need help adding a specific class to an element (class abc) when it is 100px below the top of the viewport. Currently, the class is being added to all divs instead of individual elements. Any advice on how to fix this? $(function() { $(document).scr ...

It is not possible to invoke a function within the AJAX success method

When trying to display an error message in my notify (toast) div using jQuery in Ajax success, I am encountering difficulties. Despite decoding the response from the URL properly, only .show() and .hide() functions seem to work. Although I have used conso ...

Using a React component to send data through a POST request to an API

When attempting to send a selected value from a Dropdown to an API using a POST request, I keep encountering a 405 (Method Not Allowed) error. Despite trying different ways to handle the onChange event, such as: onChange{(e) => this.onChangeHandler(e.t ...

Extracting information from a checkbox list displayed within an HTML table

I have a table with multiple rows and two columns in each row. The first column contains text, and the second column consists of checkboxes. While I was able to retrieve the values from the first column, I am struggling to fetch the values of the selected ...

Exploring creative art with Three.js streaming

I'm seeking advice on the best way to handle a large amount of data from a stream in Three.js, without needing to store it in memory for the entire application's lifespan. In traditional WebGL, this is typically achieved with gl_drawArray. Howev ...