Tips for creating a dynamic animation of a ball following a curved trajectory with CSS3

Looking to create a cool animation where a ball moves along a curved path? Struggling to figure out how to do it with CSS3 since there's no built-in path animation feature?

Wondering if it's possible to animate a ball on a curved background?

Catch the Live Demo here!

This is my code:

div.path {
  background:url(https://dl.dropboxusercontent.com/u/10268257/images/path.png) no-repeat center bottom;
  width:397px;
  height:66px;
  position: relative;
}

div.ball {
  background : green;
  width:20px; height:20px;
  border-radius:50%;
}
<div class="container">
  <div class="path">
    <div class="ball"></div>
  </div>
</div>

Answer №1

While this may not offer a comprehensive solution to your inquiry, you specifically inquired about defining a path in a CSS animation. Here is a demonstration of how you can achieve that:

JSFIDDLE Example

div.ball {
    background: blue;
    width: 30px; height: 30px;
    border-radius: 50%;

    -webkit-animation: myOrbit 6s linear infinite; /* Chrome, Safari */
    animation: myOrbit 6s linear infinite; /* Firefox, IE, Safari */
}

@keyframes path {
    0% { transform: translate(10px, 0) }
    25% { transform: translate(0, 20px) rotate(90deg) }
    50% { transform: translate(-20px, 40px) rotate(180deg) }
    75% { transform: translate(50px, 55px) rotate(270deg) }
    100% { transform: translate(150px, 50px) rotate(360deg) }
}

By examining the code provided, you'll observe the systematic definition of the ball's movement through specified X and Y coordinates.

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

Improved method for displaying information on a webpage using php and ajax technology

For my website-webservice project, I am required to fetch data from a database and perform calculations. I'm trying to determine the most efficient method for the user. Option 1: Utilize a XXXX.php file with AJAX functions to pass parameters and echo ...

What is the best way to stop a jQuery event listener on a button within a form from triggering upon the user hitting the Enter key?

Here is an example of a form containing a button: <form> <input type="text"> <button>Click Me</button> <input type="submit" value="Submit"/> </form> Using the following JavaScript: $('form').subm ...

Positioning an Image Within the Center Using Bootstrap

I recently modified some code to create a transparent background for my logo on top of a parallax image. However, after making these changes, I noticed that the logo no longer appears in the center of the screen. Can someone help me identify what could be ...

Arrangement of label and input field on my webpage

I am looking to vertically align all the fields one below another. Currently, they are randomly aligned with Bootstrap CSS. The desired layout should look like this: Label1: Textbox1 Label2: Textbox2 Here is the code snippet: Which class should I use to ...

sending user's name input using ajax

I am working on a script that saves item positions in a database. var set = $('#set'); var set_x = set.offset().left; var set_y = set.offset().top; var id = <?php echo $id ?>; $( "#set div" ).draggable({ stack: " ...

Modifying the color scheme of Bootstrap

In order to simplify referencing, I am establishing new theme colors as shown below, allowing me to use classes like bg-red instead of bg-danger or text-purple, and so forth. $primary : #24305e; $blue : #375abb; $indigo : #796eff; ...

Showcasing pictures with a prominent large image accompanied by two smaller ones on the right side

In my use of Material-ui-next, I am attempting to create images in a specific layout. ------ --------- | | | | 2 | | | | 1 |---| | | | | 3 | ------ --------- I have encountered some unusual issues. 1 - 3 appears below 1 ...

The clearfix feature fails to function properly with overflow:auto

I could really use some help with my CSS skills: Here is the HTML code I am working with: <!doctype html> <html lang="en"> <head> <meta charset="utf-8"> <title>Cluster Test</title> <link rel="stylesheet" href= ...

Outformatted Layout in HTML Email on Outlook, Post-Image Loading

When I send HTML emails in Outlook, I encounter a problem. Initially, the images do not appear when I view the newsletter, but the table layout is fine. However, once I download the images and they fit perfectly in their cells, the layout suddenly breaks ...

Discover the magic of using jQuery's .map() method with

$(function() { $('input[type=checkbox]:checked').map(function() { alert($("#chk_option").val()); $("#chk_option").val(this.value); }).get(); }); HTML code <div> <center> <form id="form_tarif" class="form-horizo ...

Error message: "jQuery is not defined and occurs exclusively in Chrome."

I've been using the following code to asynchronously load my JavaScript in the head section: <script type='text/javascript'> // Add a script element as a child of the body function downloadJSAtOnload() { var element4= document.creat ...

Limiting overflow:visible to input and select fields only

I'm currently facing an issue with a Lightning Web Component in Salesforce, however, I believe the root cause of this problem is not specific to this platform. Within my container div, I have row divs displaying select/combobox fields that need to ex ...

The jQuery calendar malfunctions on desktop devices but functions properly on mobile devices

Experiencing an unusual issue with the jQuery calendar on my website. The code is within a block (widget) in the Flatsome theme on Wordpress, and I'm using the same block for both desktop and mobile versions of the header builder. Strangely, the calen ...

Automatically integrating Nivo Lightbox into your website

I incorporated Nivo Lightbox into my website, seamlessly integrating all images with the plugin using the following code: <div class="portfolio-item"> <div class="portfolio-thumb "> <a class="lightbox" data-lightbox-type="ajax" title="Strat ...

Creating a Dynamic Counter for Real-Time Message Updates in a Personal Messaging Application with jQuery

I am currently in the process of developing a Personal Message System for my website. My goal is to have the number of new messages in each chat displayed and updated in real-time, just like the red "box" showcased in the screenshot below: https://i.sstati ...

Ajax response values overlap

I am developing an application that requires multiple Ajax requests, but I encountered a problem where I am receiving the same response values for both requests. Each request must include a data field called activityCode, yet I keep getting the value of Sc ...

Modifying Bootstrap Alert Styles with Jquery

I have an alert in my HTML form as shown below: <div class="alert bg-danger text-white alert-dismissible" id="alert" > <button type="button" class="close" data-dismiss="alert"><span>& ...

How should I refer to this style of font?

After trying to implement a font from bulletproof @font-face as a template for my website, I am facing issues. My goal is to utilize the perspective-sans black regular font. Despite uploading the necessary files - including the css style sheet provided in ...

Troubleshooting problem with local storage: JSON/JQuery items not appearing on display

My goal is to retrieve and organize all the items in localStorage and display them on an HTML page. Here is my approach: <script> function ShoppingCart() { var totalPrice = 0; var output; var productName; var productAlbum; var ...

Looking for Sha1 encryption functionality in jQuery or JavaScript?

I am currently using sha1 encryption coding in PHP <?php echo hash('sha1', 'testing'.'abcdb'); ?> However, I need this encryption to work on a page named xyz.html, causing the current block of code to not function prop ...