Moving pictures using css3 transitions

Trying to create a straightforward image slider.

Below is the provided JavaScript code:

$(document).ready(function() {
  $('#slide1_images').on('click', 'img', function(){ 
    $("#slide1_images").css("transform","translateX("+$(this).index() * -450+"px)");
  });
});

The issue seems to be that it doesn't register a click on the correct image but rather on the next one. Any suggestions?

Here's a live example:

http://jsfiddle.net/y4BkQ/

Answer №1

The .index() method will provide a zero-based index value. To adjust for human readability, the formula used is ($(this).index() + 1) * 450.

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

The app constantly requests permission for geolocation services

While experimenting with the geolocation API, I encountered an issue where my page kept repeatedly asking for permission upon refresh. To work around this problem, I attempted to save my coordinate data to local storage but encountered difficulties in ma ...

Tips for including dynamic textbox input into a database using the combination of Ajax and PHP

I am facing an issue with a dynamic textbox inside my bootstrap modal. It only saves the first item entered, but when using the native submit without Ajax, it captures all data. I am unable to identify the problem in my Ajax code. My goal is to insert al ...

Using app.js in a blade file can cause jQuery functions and libraries to malfunction

In my Laravel application, I am facing an issue with my vue.js component of Pusher notification system and the installation of tinymce for blog posts. Adding js/app.js in my main layout blade file causes my tinymce and other jQuery functions to stop workin ...

What steps can I take to enable search functionality in Ckeditor's richcombo similar to the regular search feature in

I am currently developing a custom dropdown menu using the rich combo feature in CKEDITOR. One of my goals is to include a search functionality within the dropdown, such as a key press search or an input textbox search. This is how my dropdown box appear ...

Vue.js template is failing to properly render hyperlinks, although basic string output is functioning as expected

Whenever I print attrib.link, everything works perfectly fine, <div v-for="attrib in attributes"> {{ attrib.link }} </div> However, when I try: <div v-for="attrib in attributes"> <a target='_blank' href={{ attrib.link } ...

I was disappointed by the lackluster performance of the DataTable in CodeIgniter; it did not

I recently started using CodeIgniter and I'm having trouble getting the dataTable to work. Here's a snippet of my page: <table class="table table-striped table-bordered table-hover dataTables_default" id="dataTables-example"> ...

Can an if-statement be utilized in an Ajax scenario?

I'm currently developing a web application that enables users to post messages on a page. There are two ejs files involved in this process: index.ejs contains the form for users to input information and displays a list of usernames and messages re ...

Assign the Firebase token to the JavaScript cookie value

Can a cookie store a token value? In my setup with js-cookie, Firebase auth/firestore, and Next.js, I am setting my cookie within the handleUser function like this: const handleUser = async (rawUser) => { if (rawUser) { const user = await fo ...

The CSS dropdown menu is malfunctioning on Internet Explorer and Firefox

After searching for a solution and coming up empty-handed, I have decided to ask a question. The drop-down menu on my computer and other devices at home works perfectly in Chrome but not in Firefox and IE. #menu { position: absolute; left: 50%; bottom ...

Wordpress is experiencing a recurring issue with scripts being loaded multiple times

Currently, I am attempting to load some of my scripts from CDNs such as CDNjs and Google. While the scripts are loading correctly, I have noticed a strange issue where each script seems to generate two or even three HTTP requests (for the same script). You ...

Tips for troubleshooting an Angular error when no specific information is provided

I'm encountering an error `ERROR Error: "[object Object]" in my console and my app is displaying a white screen. Everything was working perfectly fine before, and I can't pinpoint any changes that may have caused this issue. The error appears to ...

Establishing the properties of an object as it is being structured within a nested data format

I am in the process of creating a unique JSON representation, focusing on object composition to directly set key values during composition. However, I've encountered difficulty composing multiple objects in a nested manner. My goal is to find an expr ...

How to display currency input in Angular 2

Is there a way to dynamically format input as USD currency while typing? The input should have 2 decimal places and populate from right to left. For example, if I type 54.60 it should display as $0.05 -> $0.54 -> $5.46 -> $54.60. I found this PLUNKER that ...

Using jQuery to detect and respond to changes in an asp:RadioButtonList

Upon page load and when a user selects a radio button, the code below focuses on a textbox. However, I am looking to modify it so that if the last radio option "Mail" is chosen, the focus shifts to the btnSubmit control instead of txtPayerName. $(funct ...

Alter the background color of a div contingent on the checkbox being checked within

I am in search of a solution to modify the background color of a parent div that contains a checkbox. The condition is that the background color should only change when the 'checked' attribute is present within the tag. HTML <div class="comp ...

Sending data to a PHP file with JQuery Ajax: A step-by-step guide

My goal is to utilize jQuery and ajax to transmit information to a php file. However, I am facing an issue where I can only retrieve the response from ajax in json format and unable to successfully send the data. $.ajax({ url: 'myFile.php' ...

Vue 3's "<Component :is="">" feature magically transforms camelCase into lowercase

Within my application, I have implemented a feature where users can customize the appearance of social media links on their page by defining which platforms they want to include. Each social media platform is represented by its own component responsible fo ...

The Angular directive ng-if does not function properly when trying to evaluate if array[0] is equal to the string value 'Value'

In my code, I want to ensure that the icon is only visible if the value at array index 0 is equal to 'Value': HTML <ion-icon *ngIf="allFamily[0] === 'Value'" class="checkas" name="checkmark"></ion-icon> TS allFamily = [ ...

The IMG directory cannot be stored in the database but can be viewed using the same variables used in the query

I'm facing an issue while trying to upload an image to my server using a form created by Sanwebe. You can find the form here. After pressing the upload button, the new thumbnail loads perfectly fine. However, for some reason, the image is not being up ...

Executing Javascript on Selenium RC with PHP is a crucial skill to have in your toolkit

Is there a way to execute Javascript from Selenium RC? I have been trying different methods with no success so far. I attempted the following approach: I created a custom function in user-extensions.js: function sayhello() { document.write('hel ...