Looking to make changes to the updateActivePagerLink setting in JQuery Cycle?

I'm in the process of developing a basic slideshow with 3 images, and I am relatively new to Jquery and Cycle. The slideshow is functioning properly, and the 3 pager links are also functional.

The only remaining task for me is to implement "activeSlide" functionality to the currently selected pager image. This cannot be achieved through CSS by simply applying the activeSlide class because I want to change the image source of the active pager when it is selected. If it were just simple text numbers by default, I could easily style the activeSlide class.

Essentially, my goal is to switch test-select-off.jpg with test-select-on.jpg when the active slide pager is reached.

Cycle code:

$(function() {
    $('#testimonial-features').cycle({  
        speed: 800,
            timeout: '6500',
            pause: 'true',
            pager: '#testimonial-switcher',
            pagerAnchorBuilder: function(idx, slide) { 
             return '#testimonial-switcher li:eq(' + idx + ') a';       
            } 
    });
});

HTML code:

<div id="testimonial-switcher">
<ul>
    <li><a href="#"><img src="images/layout/test-select-off.jpg" /></a></li>
    <li><a href="#"><img src="images/layout/test-select-off.jpg" /></a></li>
    <li><a href="#"><img src="images/layout/test-select-off.jpg" /></a></li>
</ul>

How can this be accomplished? It seems like I might need to make adjustments in the updateActivePagerLink option by modifying the updateActivePagerLink function, which can be found at :

$.fn.cycle.updateActivePagerLink = function(pager, currSlideIndex) { 
    $(pager).find('li').removeClass('activeLI') 
        .filter('li:eq('+currSlideIndex+')').addClass('activeLI'); 
}; 

Since I am still learning the syntax, any guidance would be highly appreciated!

Answer №1

UPDATE: It seems my initial response was incorrect as I wasn't familiar with the plugin you are using. However, based on your findings, I have a revised solution for you. Simply modify all instances to 'off' at the beginning of the function (line 1), then change the active one to 'on' as you added.

$.fn.cycle.updateActivePagerLink = function(pager, currSlideIndex) {
    $(pager).find('img').attr('src','images/layout/test-select-on.jpg');
    $(pager).find('li').removeClass('activeLI') 
            .filter('li:eq('+currSlideIndex+')').addClass('activeLI')
            .find('img').attr('src','images/layout/test-select-on.jpg'); 
};

Please let me know if this resolves the issue.


Misleading Original Answer: (Keeping it for context)
It appears that by changing the src of the img within the li tagged as
.activeLI</code during the <code>after
callback function could potentially solve your problem (though my knowledge of the Cycle plugin is limited and mainly from the docs).

Therefore, adjust the Cycle code like so:

$(function() {
    $('#testimonial-features').cycle({  
        speed: 800,
        timeout: '6500',
        pause: 'true',
        pager: '#testimonial-switcher',
        pagerAnchorBuilder: function(idx, slide) { 
         return '#testimonial-switcher li:eq(' + idx + ') a';       
        },
        after: function(curr, next, opts) {
         $(curr).find('img').attr('src','images/layout/test-select-on.jpg');
        } 
    });
});

Kindly confirm if this improves the situation! (Note: if not successful, consider removing the wrapping $() from the curr in the after: function()... given my lack of experience with the plugin)

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

Modify the initial header tag within the document to be <h1> instead of <h2>, <h3>, ... <h6>

In the event that the <h1> tag is not present, the script will search for the first header tag in the document (either <h2> through <h6>). If the text within this tag matches the title text, it will be converted to <h1 class="heading1" ...

Manipulating background scrolling using jQuery

I had a vision of creating a logo with PNG transparency and a scrolling background that would give the appearance of being made in Flash. To achieve this effect, I utilized the jquery.backgroundPosition.js plugin for enabling background scrolling. Here is ...

The webpage is not refreshing or reloading despite using window.location.href

When creating a refreshcart() function, the window.location.href is assigned to currentUrl. However, when making an ajax call in the else block with window.location.href = currentUrl, true; it does not successfully refresh the page. $(document).ready(fu ...

breaking down the bootstrap grid into smaller grids

In my web application, I utilized bootstrap to ensure responsiveness across all devices. I have segmented the main row into three columns (e.g. the second row). Now, I am looking to further divide each of these columns into sets of 12 columns each (akin to ...

Arrange jQuery UI elements in descending order

I need to rearrange a list in descending order, starting from the highest value down to the lowest. The values are currently listed as 10,9,8,7,6,5,4,3,2,1 and I need to update the data-ids accordingly. jQuery('.photos').sortable({ stop: f ...

Java Function for Cleaning HTML Id Attributes

Looking for a more elegant solution to sanitize HTML ID attributes? /** * * HTML 4 Specification * ID and NAME tokens must begin with a letter ([A-Za-z]) and may be followed by any number * of letters, digits ([0-9]), hyphens ("-"), underscores (" ...

Illuminate XHR 500 (Server Side Issue)

I'm currently troubleshooting an issue with this AJAX script, but I'm unable to identify the specific problem. The Chrome developer tools are indicating a "500 (Internal Server Error), doWork @ (index):16 , onclick @ (index):28" Is there anyone ...

Efficiently storing images fetched via Ajax using JQuery

I have a page that loads multiple pictures asynchronously multiple times. Currently, I am doing the following: $('#map').append('<div id="'+(x.ID)+'"> <img id="pic" src ="'+x.src+'"> </div>'); H ...

What are some methods to design distinct angular ui bootstrap dialogs?

Is there a way to customize angular-ui bootstrap modal dialogs so that they have distinct colors and sizes from each other? I can style them globally for the site but not individually. I came across a similar question, but it only addresses changing all d ...

A guide to using jqGrid: Retrieve the value of a particular cell by double clicking on a row

Is there a way to implement a feature where users can double click on any part of a row and have it open a new HTML page based on the specific content in a cell? For example, I have a table with different counties in New York listed in separate rows: Coun ...

Tips on how to ensure the navigation menu is the same size as its child elements in the navigation menu

I'm currently designing a navigation menu that includes a child navigation menu. My goal is to have the size of the main navigation menu match that of the child navigation menu. To achieve this, I've created three hyperlink tags followed by a di ...

Stand out with Bootstrap's wide card design

Does anyone know how I can correct the image display issue within this card using Bootstrap 4? I am attempting to adjust the picture so that it is perfectly scaled to fit within a fixed height card. Currently, the image appears stretched and I am explorin ...

Error Encountered: Django - AJAX Request Not Found

I'm currently working on building an ajax function that, when triggered, should display information in a newly created modal. I seem to be encountering an error that says "not found" every time I attempt to access the specified URL. Below is a screens ...

Using HTML nested lists in Wordpress sites

Working on nested, ordered lists using ol types and encountering an issue where the code appears correctly in Wordpress preview but displays incorrectly in Firefox and IE. The lists are showing as numbered instead of the specified types in the code provide ...

Preventing background style from taking precedence over backgroundColor style in React's inline styling

What causes background to take precedence over backgroundColor in React inline-style? In this scenario, the lack of a specified green background-color results in the background gradient with transparency transitioning into white rather than green within t ...

Issue encountered while transferring data using Ajax

I am a novice in the realm of ajax and currently immersed in a project that demands passing data from an ajax function to a php page for the purpose of dynamically generating and displaying modals. Although I am successful in creating the modal, I suspect ...

We'll show you the steps to properly organize a set of radio buttons created dynamically within a 'controlgroup' using jQuery Mobile

I am facing an issue with grouping dynamically generated radio buttons into a jQuery Mobile control group. I generate the radio buttons and append them to a div, but they are displayed separately even though the wrapping div contains a 'controlgroup&a ...

Using Geolocation in HTML5 and JavaScript

Currently, I am working on my debut mobile web application and have successfully integrated Google Maps into it using Geolocation JavaScript API version 3. Now, I am looking to add a button that, when clicked by the user, centers the map on my location o ...

When jQuery is combined with extending Object.prototype, the result is an error message that states, "c.replace is not

In my open source project, I am utilizing jQuery 1.5 and the following snippet is included in my JavaScript code: /** * Object.isEmpty() * * @returns {Boolean} */ Object.prototype.isEmpty = function () { /** * @deprecated Since Javascript 1.8 ...

Assistance required: The database is not found upon page reload. How can this be resolved?

My HTML5 code has created a database with create, add, delete, and print operations. However, the ObjectStore is re-created every time I load the page, and the additional values stored are not present upon reloading the page. What could be wrong with my ...