Adjusting the position of keyframes on an element

<div id="carousel">
    <figure>
        <img src="http://www.codehub.com/css-carousel/images/slides/a.png" />
        <img src="http://www.codehub.com/css-carousel/images/slides/b.png" />
        <img src="http://www.codehub.com/css-carousel/images/slides/c.png" />
        <img src="http://www.codehub.com/css-carousel/images/slides/d.png" />
        <img src="http://www.codehub.com/css-carousel/images/slides/e.png" />
    </figure>
</div>
<style>
    @keyframes sliding {
    0% { left: 0%; }
    25% { left: -100%; }
    50% { left: -200%; }
    75% { left: -300%; }
    100% { left: -400%; }
    }
    body { margin: 0; } 
    div#carousel { overflow: hidden; }
    div#carousel figure img { width: 20%; float: left; }
    div#carousel figure { 
    position: relative;
    width: 500%;
    margin: 0;
    left: 0;
    text-align: left;
    font-size: 0;
    animation: 30s sliding infinite; 
    }
    .css-slider-mask{
    width:300px;
    height:300px;
    }
</style>

How can I adjust the current image position on the carousel? I have tried

document.querySelector('figure').getBoundingClientRect()
ClientRect {top: 0, right: 930.609375, bottom: 0, left: -569.390625, width: 1500…} 

But when I attempt to change it using

document.querySelector('figure').style.position.left = '-110px'

The view remains unchanged! Why is that?

I am looking to modify the animation position. Does JavaScript provide access to the keyframe object for this purpose?

Answer №1

When keyframe animations are active, properties set within them take precedence over other styling rules. In the case of the figure element with a continuously running animation affecting its left property, direct changes to this property will not be visibly reflected.

After selecting a specific value for the left property, what action do you want the animation to perform?

  • To instantly move to the desired location and halt there, simply turn off the animation by adding animation: none;
  • If you wish to pause the animation at a certain point and resume it later, you will need to manage the animation more precisely using JavaScript. CSS animations always start from 0% (or 100% if in reverse) when triggered; they cannot restart from an arbitrary position in the middle once deactivated.

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

Utilizing jQuery to Adjust Tab Transparency

I'm trying to add some opacity to my jQuery tabs, but so far I've only been successful with accordions. Any tips or tricks for achieving this effect with tabs? Styling with CSS .ui-tabs{ background-image: none; background: rgba(204, 204 ...

Tips for launching a web application using Nuxt with Firebase

After successfully installing the Nuxt Firebase plugin into my web app, everything works flawlessly when I run the generated folder (dist) locally. However, once I deploy it to the server, my web app fails to recognize any Nuxt Firebase commands and throws ...

Comparing XDomainRequest and XMLHTTPRequest - which one to choose

Our team is currently developing an application utilizing PixiJS that integrates a dynamic json loader. The .json files are loaded using the following logic: if(window.XDomainRequest) { this.ajaxRequest = new window.XDomainRequest(); } else if (windo ...

In Vue/Javascript, once the user reaches the top of the page, automatically scroll down to reveal an extra navigation bar

My goal is to achieve something similar to what is being done on Snapzu.com: When you reach the top of the window, you can keep scrolling to display different categories. I am looking to implement this functionality using Vue or Javascript, but I haven&ap ...

Symphony 5 and Encore: Issue with Bootstrap JS Loading

Encountering issues while trying to integrate Bootstrap's js with Symfony 5, encore, stimulus, etc... All required dependencies like jquery, popper, corejs are installed and functioning, except for Bootstrap's JS components. The compilation of ...

Experience a unique custom layout using AppRouter in Next.js version 13, with the added

My goal is to encapsulate the _app.js file within a custom layout, similar to what I have done before. This way, I can include a Navbar at the top and wrap everything else within a container: //layout.js file import { Container } from 'react-bootstrap ...

The AJAX request was successful, however, the PHP script did not return any

When using an Ajax success function to alert data in JavaScript, there may be occasions where the PHP side shows that the GET array is empty. <script type="text/javascript"> var myArray={ name:"amr", age:22 } myArray =JSON.stringify(myA ...

What is the best way to display a button only during office hours from 9am to 5pm using React.js or JavaScript?

If I want a button to only be visible from 9am to 5pm, how can this be achieved where the button is hidden outside of that time frame? ...

Adjust the size of the Vimeo video to fit the container dimensions and eliminate any black bars

Is there a way to eliminate the black bars that are present in the vimeo video which has been embedded? Below is the link to the code snippet. JSFiddle Link <div class="embed-container"> <iframe src="https://player.vimeo.com/video/86019637?title= ...

The numerical value fluctuates upon utilizing JSON.parse( )

I am currently utilizing Node/Express to send API requests to the unofficial Vine API. The data returned by the GET https://api.vineapp.com/users/search/ route undergoes changes during parsing. This is my code snippet: request({ url: 'https://api.v ...

unable to eliminate the pause/play button when a different video is selected

Recently, I added three videos to my webpage with a feature that displays play/pause buttons upon single-clicking on the video. However, I am facing difficulty in removing the pause/play button from videos that are not currently being clicked. Additionally ...

Is there a way to extract all the class names from a JavaScript file?

I am currently working on developing a code to showcase all the public properties of a class that are available in a JavaScript file. As of now, the user has to manually input the name of the class in a text box. However, my goal is to enhance user experie ...

Issue with identifying if an element has a specific class in jQuery

Utilizing bootstrap tabs, I wanted to execute some JavaScript functions when a LI element is clicked. However, I only want these functions to run conditionally based on whether the tab is already active or not. I attempted to create code that checks if th ...

Learn how to transform the html:options collection into html:optionsCollection

What is the best method to transform this code snippet: <html:options collection='catList' property='catId' labelProperty='catName'> using the <html:optionsCollection> tag? ...

Creating a dynamic menu using Material Design Lite and ng-repeat

My goal is to implement menu features using MDL. Initially, I had success with the static implementation shown in the code below. <button id="demo-menu-lower-left" class="mdl-button mdl-js-button mdl-button--icon"> <i class="material-icon ...

Execute an API request when initializing the default value for MUI Select

Issue : Executing onChange Event with Default Value in Material-UI Select Component Upon running this React component, a Material UI Select Component will be displayed with a default selected option of 10 set using the useState hook. The challenge is to t ...

Obtain deeply nested JavaScript objects within a Django view and format them as a dictionary

In my simple view, I am dealing with an ajax request that includes a javascript object. The jquery request code is as follows: $.get(URL, {'kwargs': {test: 1}}, function(data){//whatever}) The issue here is that the request.GET now shows a stra ...

How can I retrieve an empty object from the database using Angular 5?

Hey there! I'm facing a little issue that I need help solving. I asked a question before when things weren't clear, but now they are (you can find the previous question here). I'll share my code and explain what I want to achieve shortly. H ...

Mixing box-shadow and blur filters can result in unusual artifacts appearing in Webkit browsers

Recently, I encountered an intriguing and frustrating bug in WebKit browsers. Consider a scenario where there is a parent DIV (let's say .wrapper) and a child DIV (.main). You apply a box-shadow on the .main DIV and a blur filter on the .wrapper DIV. ...

Ways to retrieve updated fields sent with automatic refresh functionality

Is there a way for changes made by users on a webpage that automatically refreshes to be submitted and sent to the server without using ajax calls? The current method of making an ajax call every time a field is changed seems like overkill. If you have any ...