Implement a jQuery slideshow with a full background image, aiming to set up a clickable link on the final image of the

Could someone please help me with a query I have regarding a background image slide show using jQuery code? I have set up a slide show with multiple images and would like to make the last image clickable. Is it possible to achieve this specific functionality?

Here is the link to what I have done so far for reference:

The plugin I am using is BGSLIDER-INIT.JS

/*global $:false */
/*global window: false */

(function(){
  "use strict";

$(function ($) {

//BG SLIDESHOW WITH ZOOM EFFECT
$.mbBgndGallery.buildGallery({
            containment:"body",
            timer:1300,
            effTimer:1300,
            controls:false, //updated in v1.1
            grayScale:false,
            shuffle:false,
            preserveWidth:false,
            preserveTop: true,
            effect:"fade",

             images:[
             "images/bg/01.jpg",
             "images/bg/02.jpg",
            "images/bg/03.jpg",
            "images/bg/04.jpg",
            "images/bg/05.jpg",
            "images/bg/06.jpg",


             ],

            onStart:function(){},
            onPause:function(){},
            onPlay:function(opt){},
            onChange:function(opt,idx){},
            onNext:function(opt){},
            onPrev:function(opt){}
        });

});
})();

I am looking to make the last image (image06) clickable. Could someone guide me on how to modify the code to add this interactivity? I also want to link it to a section on my page and assign a scroll class to it.

Answer №1

It appears that the slideshow is using a div class called "mbBgndGallery" to set a background. Although the slideshow isn't functioning properly for me at the moment, I suspect that this plugin is replacing the img src. Assuming that you are aware of which image is the last one in the slideshow, it seems to be "images/bg/06.jpg". Therefore, I would suggest writing something like this:

 if($('.mbBgndGallery img').attr('src') === 'images/bg/06.jpg') {
     $('.mbBgndGallery').on('click', function() {
         window.location = "someURL.com";
     });
 }

Keep in mind that this if statement will only be executed when the page loads. Ideally, this code should be integrated directly into the plugin itself. However, if you are unsure how to do so, setting an interval to check each time the image changes might be a solution. Since it appears that images are being changed every 1300 ms, set an interval for approximately the same amount of time with a slight offset.

 var i = setInterval(function() {
    if($('.mbBgndGallery img').attr('src') === 'images/bg/06.jpg') {
       $('.mbBgndGallery').on('click', function() {
           window.location = "someURL.com";
       });
    }
 }, 1350);  

Answer №2

Utilize the .click() method in jQuery:

$('.mbBgndGallery').click(function() {
    $(this).find('img').each(function() {
        if( $(this).attr('src') == 'images/bg/06.jpg' )
            PERFORM CLICK ACTIONS
    });
});

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

How to properly Open a "div" Element by its ID in ReactJS

Today, I want to share an issue that I've been facing. To simplify things, I have mapped a BDD, The result of this mapping is displayed in multiple cards, There's a button that when clicked opens up more details on the map, But here's wh ...

Guidelines for creating an auto-scrolling React Native FlatList similar to a Marquee

I currently have a FlatList component set up in my project. <FlatList horizontal data={data} key={(item, index) => index.toString()} ListHeaderComponent={listHeader} renderItem={ // renderin ...

Getting a JSON object from a GET request in Flask: A step-by-step guide

My backend server is built using Flask, while my frontend client utilizes JavaScript with jQuery-Ajax to communicate with the server. I have successfully been able to retrieve JSON objects from a POST request, but encountering difficulties when attempting ...

Tips for utilizing the standard search functionality of Select2 while also implementing a remote data source

Even though I am able to populate the dropdown from the data source, there is an issue with filtering the results using the search field at the top. If I make an AJAX request to the API, fetch the data, create <option> elements for each result, and a ...

What could be causing Vuejs to not update elements promptly?

Currently, I am encountering a scenario where I am adding options to a select element using Vue.js when the @change event of that specific element is triggered. An issue arises where the new option is not 'registered' until I exit the function. ...

Javascript splice method mistakenly eliminating the incorrect elements

I have an array of objects like the one below: [{"name":"Rain"},{"name":"Storm"},{"name":"Forest"}] These objects are indexed as follows: [0, 1, 2]. I'm attempting to delete an item at a specific position using this code: $scope.selectedSound ...

What is the process for incorporating a collection in Mongoose?

Trying to clear the Users collection before and after tests: before(function(done) { mongoose.connection.collections['users'].drop(function(err) { mongoose.connection.collections['users'].insert(user, done); }); }); after(func ...

Send a StringBuilder message from a JSON object in the MVC controller and display it on the view

I'm having trouble passing a StringBuilder message as extra data back to an ajax call and manipulating it on the client side. Here is how I append the message to the StringBuilder and pass it back: StringBuilder retMessage=new StringBuilder(); retMes ...

Guide on adding markers using Google Maps API based on specific criteria

Hi there, I need assistance in developing the following requirements. In my database, there is parking lot information. Let's say each parking lot has two attributes: id and address. Via a spring controller, I am passing a list of parking lots t ...

Mastering the art of manipulating arrays with jquery

Trying to implement a dynamic search bar feature using jQuery. Here is the code snippet: Fiddle : https://jsfiddle.net/fpLf1to4/ var inputSearch = $('.searchInput').hide(); var searchArray = ['s','e','a',& ...

What are the best practices for protecting a web application with login and database in the year 2022?

My knowledge of security is outdated and I am looking to update my skills in full stack development. Currently, I am exploring Oauth2, JWT, Next.JS, Auth0, and more, but I am struggling to integrate all these components together. Please bear with me as I m ...

Using ajax for transferring form data to a different php page

Hello everyone, I'm in need of assistance. I have a form on one PHP page and I want to use AJAX to pass the data to another PHP page that will update my database and then return the results. <form name="profile" class="profile"> < ...

Can you show me how to magnify multiple images when hovering over them without altering their dimensions?

I am working on a gallery that features multiple images and I want the images to zoom in when hovered over without resizing the container. My project is built using Bootstrap 4. <div class="row"> <div class="col-12"><img ...

Simple steps to access a feature on an AngularJS application

I have my angular application stored in a variable (initialized with:) var app = angular.module('app', [...]); Now, I need to access the $timeout service. How can I retrieve this service from it? I am looking for something like: var timeout ...

Validation of phone numbers based on country codes

How can I validate phone numbers based on the selected country in Angular? Are there any Angular packages specifically for this task? I've attempted to use regex, but it only works for certain countries. I need a solution that can validate mobile an ...

Guidelines for accessing the Coinbase exchange API from a localhost

Following the instructions in the Coinbase Cloud documentation, I tried running this code on the client side using JavaScript: const options = { method: 'GET', headers: { Accept: 'application/json', 'cb-access-key&ap ...

Validate if the translation file exists in ngx-translate

Is there a way to determine if a translation file exists for the language obtained from navigator.language using ngx-translate? I am looking to implement something similar to: if( isLanguageAvailable(navigator.language)) { this.translate.use(navigator.l ...

The secret to achieving perfectly even spacing along the vertical axis

I'm working on a card design that contains a div with 3 elements - 2 headers and a paragraph. I need to ensure there is consistent spacing between each element and the top/bottom of the card. Currently, there seems to be too much margin after the last ...

The primary container is brimming with an abundance of content

Can anyone help me with a CSS issue I'm experiencing in the latest versions of Chrome and Firefox? I can't seem to figure it out on my own. The problem arises with a container div that has a 50px top margin. Inside this container, there's a ...

Tips on revealing TypeScript modules in a NodeJS environment

Currently, I am working on developing a TypeScript library. My goal is to make this library compatible with both TypeScript and JavaScript Node projects. What would be the most effective approach for achieving this? Should I create two separate versions ...