Fade-in animation of a clock on an SVG image

I am trying to achieve a unique fade-in effect for an SVG image in my HTML. The challenge is to make the fade-in start from the top of the image and progress in a circular motion until it completes a full circle. An example of the effect I am aiming for is the clock transition in PowerPoint (link).

I attempted to use radial gradients as suggested here, but I could not achieve the desired result due to the transparency of the SVG image and the use of a background. The gradient approach only allows for a progressive circle from or to the center.

Below is the code I have tried so far. While it is not extensive, I am struggling to find a direction that could lead me to the desired outcome:

var isAnimProgressing = false;
$("#button1").click(function() {
  var opa = "0";
  if(!isAnimProgressing) {
    isAnimProgressing = true;
    if($(".test").css("opacity") == "1") {
      opa = "0";
    } else {
      opa = "1";
    }
    $(".test").animate({opacity: opa}, 2000, "linear", function() {
        isAnimProgressing = false;
    });
   }
});

$("#button2").click(function() {
  if($(".test").hasClass("done")) {
    $(".test").removeClass("done");
  } else {
    $(".test").addClass("done");
  }
});
body {
  background-image : url(https://cdn.pixabay.com/photo/2016/04/15/04/02/water-1330252__340.jpg);
}

.test {
  opacity: 0;
  transition: all 2s ease;
}

.test.done {
  opacity: 1;
}
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8>
<title>Document</title>
<link rel="stylesheet" type="text/css" href="styles/main.css">
  <script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
</head>
<body>
  <button id="button1">JS</button> OR
  <button id="button2">CSS</button>
<div class="test loading">
<img src='https://s.cdpn.io/3/kiwi.svg' alt='loading-cat'>
</div>
</body>
</html>

Answer №1

You have the freedom to manipulate an animated SVG mask as you please.

$("#button2").click(function() {
  document.getElementById("clocksweep").beginElement();
});
body {
  background-image : url(https://cdn.pixabay.com/photo/2016/04/15/04/02/water-1330252__340.jpg);
}
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>

<button id="button2">SVG</button>
<div class="test loading">
<svg width="612px" height="502.174px" viewBox="0 65.326 612 502.174">
  <defs>
    <mask id="reveal" maskContentUnits="objectBoundingBox">
      <rect width="100%" height="100%" fill="white"/>
      <path d="M0,0 L0,1,1,1,1,0 Z" fill="black">
        <animate id="clocksweep" attributeName="d" dur="2s" begin="indefinite" fill="freeze"
          values="M 0.5,0.5 L 0.5,0, 1,0, 1,0.5, 1,1, 0.5,1, 0,1, 0,0.5, 0,0, 0.5,0 Z;
                  M 0.5,0.5 L 1,0, 1,0, 1,0.5, 1,1, 0.5,1, 0,1, 0,0.5, 0,0, 0.5,0 Z;
                  M 0.5,0.5 L 1,0.5, 1,0.5, 1,0.5, 1,1, 0.5,1, 0,1, 0,0.5, 0,0, 0.5,0 Z;
                  M 0.5,0.5 L 1,1, 1,1, 1,1, 1,1, 0.5,1, 0,1, 0,0.5, 0,0, 0.5,0 Z;
                  M 0.5,0.5 L 0.5,1, 0.5,1, 0.5,1, 0.5,1, 0.5,1, 0,1, 0,0.5, 0,0, 0.5,0 Z;
                  M 0.5,0.5 L 0,1, 0,1, 0,1, 0,1, 0,1, 0,1, 0,0.5, 0,0, 0.5,0 Z;
                  M 0.5,0.5 L 0,0.5, 0,0.5, 0,0.5...

Answer №2

Check out this CSS animation solution that is compatible with Microsoft browsers:

$("#button2").click(function() {
  document.querySelector("#reveal").classList.add("animate");
});
body {
  background-image : url(https://cdn.pixabay.com/photo/2016/04/15/04/02/water-1330252__340.jpg);
}

#reveal circle {
    stroke-dasharray: 3.15px;
    stroke-dashoffset: 0px;
}
#reveal.animate circle {
    animation: clocksweep 2s linear forwards;
}

@keyframes clocksweep {
    100% { stroke-dashoffset: 3.15px; }
}
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>

<button id="button2">SVG</button>
<div class="test loading">
<svg width="612px" height="502.174px" viewBox="0 65.326 612 502.174">
  <defs>
    <mask id="reveal" maskContentUnits="objectBoundingBox">
      <rect width="100%" height="100%" fill="white"/>
      <circle r="0.5" cx="0.5" cy="0.5" transform="matrix(0,-1,-1,0,1,1)" fill="none" stroke="black" />
    </mask>
  </defs>
  <g mask="url(#reveal)">
    <ellipse fill="#C6C6C6" cx="283.5" cy="487.5" rx="259" ry="80"/>
    <path id="bird" d="M210.333,65.331C104.367,66.105-12.349,150.637,1.056,276.449c4.303,40.393,18.533,63.704,52.171,79.03
 c36.307,16.544,57.022,54.556,50.406,112.954c-9.935,4.88-17.405,11.031-19.132,20.015c7.531-0.17,14.943-0.312,22.59,4.341
c20.333,12.375,31.296,27.363,42.979,51.72c1.714,3.572,8.192,2.849,8.312-3.078c0.17-8.467-1.856-17.454-5.226-26.933
c-2.955-8.313,3.059-7.985,6.917-6.106c6.399,3.115,16.334,9.43,30.39,13.098c5.392,1.407,5.995-3.877,5.224-6.991
c-1.864-7.522-11.009-10.862-24.519-19.229c-4.82-2.984-0.927-9.736,5.168-8.351l20.234,2.415c3.359,0.763,4.555-6.114,0.882-7.875
c-14.198-6.804-28.897-10.098-53.864-7.799c-11.617-29.265-29.811-61.617-15.674-81.681c12.639-17.938,31.216-20.74,39.147,43.489
- More text content here -

</svg>
</div>

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

Can a personalized user permission prompt be designed for HTML5 APIs?

Can a consistent custom user permission request dialog be designed for HTML5 APIs, such as geolocation or getUserMedia, to ensure uniform appearance on all browsers? ...

I am having trouble getting my textarea to accept width attributes

Strangely, the text area on my website just won't cooperate with the width I specify. I've double-checked the CSS multiple times to no avail! Take a look at this jsfiddle example that demonstrates what I'm trying to achieve. However, on my ...

Achieve a flat text indentation similar to an ordered list using CSS

Is there a way to format my FAQ Q & A like an ordered list? <div class="col-left"> <h3><strong>CAPTION</strong></h3> <ul> <li>Q: Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Sed non risus. Suspe ...

Choosing individual child elements, with matching names, from two distinct parent elements with identical names

As a beginner in coding, I understand that my code may be messy and redundant, so I apologize for any confusion it may cause. I am working on adding the final piece to my navigation bar. Below is the HTML code, and a fiddle link will be provided at the en ...

JQuery not properly validating inputs with required attributes after creation

I am currently developing a contact form that includes an "alternative address" <div id='alt'> with toggleable visibility. Inside this div, there is a required <input> field. I encountered an issue where toggling #alt twice (thus hidi ...

Troubleshooting date range validation in jQuery

I am facing an issue in my code where I have a set of start and end date fields that need to be validated to ensure the start date comes before the end date. I am currently using the jQuery validation plugin for this purpose. For reference, here is the li ...

Navigating fluently in React Native applications

Struggling to grasp the proper implementation of navigation in RN? The provided code snippet should shed light on the current scenario. HeaderConnected is equipped with a menu button component that utilizes a custom navigate prop for opening the Drawer me ...

The AJAX request contains additional parameters in the URL, such as http://localhost:1964/a/b?_=1830

Can someone explain why the URL changes to /a/b?_=1830 and returns a 500 (Internal Server Error)? $.ajax({ url:'/a/b', type: 'GET', cache: false, async: false, dataType: 'JSON', ...

Troubleshooting Issue with Mongoose Virtual Field Population

I am currently facing an issue with my database due to using an outdated backend wrapper (Parse Server). The problem arises when dealing with two collections, Users and Stores, where each user is associated with just one address. const user = { id: &q ...

Warning: React has detected that a non-boolean value of `true` was received for the attribute `my-optional-property`

source code import React from "react"; import { Button, ButtonProps } from "@material-ui/core"; interface MyButtonProps extends ButtonProps { "aria-label": string; "my-optional-property"?: boolean; } function MyCustomButton(props: MyButtonProps) { ...

Exploring MongoDB querying with two keys in conjunction with Express JS and NodeJS

I'm seeking assistance with my web application developed using Express JS and Node. I am encountering issues with the .find() command when trying to search for multiple words. It's interesting because using the $all command works when two words ...

Accessing PageController through XmlHttpRequest is not allowed in Shopware 6

I'm encountering an issue when attempting to send a request to my customized StorefrontController on the most recent version of Shopware 6.2.2. The error message I'm receiving is: PageController can't be requested via XmlHttpRequest. I&apos ...

jCarousel jQuery plugin malfunctioning on iPhone devices

I am currently implementing a vertical carousel to showcase video thumbnails using sorgalla.com/projects/jcarousel/. When the thumbnails are clicked, the source of the larger video changes accordingly. My website has two versions - one with Flash navigati ...

The form does not support inserting all values through AJAX. We may need to implement a QUERY to handle this

Can someone help me find the issue in my code? I have checked the back end and can't seem to identify the logic error. The form submission shows as successful but does not insert the values into the database. I'm still learning how to use ajax, s ...

Discovering relative URLs within an MVC 4 framework

Seeking a solution for storing the fully qualified URL of a relative path in MVC: ~/Content/themes/base/jquery-ui.min.css" In my scenario, I have a hidden input field: <input type="hidden" id="siteUrl" value=""/> I attempted to populate this hidd ...

"Triggering CSS changes with the click of a

I am developing a basic calendar application in PHP and I would like to dynamically change the style of the <td> block based on user interactions. Specifically, I want to implement a behavior where once the "menuclick" class is active, the other cl ...

Bidirectional data binding in angular 12 reactive forms

After working with angular for a while, I encountered an issue while trying to implement two-way binding. The code snippet below is where I'm facing difficulty. Since the use of [(ngModel)] has been deprecated in Angular 12 within formGroup, finding ...

Display only one field and hide the other field using a jQuery IF/ELSE statement

Hey there! I have a situation where I need to toggle between two fields - one is a text field and the other is a text_area field. When a user clicks on one field, the other should be hidden and vice versa. I've tried using JQuery for this: $(document ...

Tips on managing ASP .NET API's HttpResponseMessage for file downloads

I came across a solution on how to download a file from an asp.net API at this link: As a result, I created an API handler with the following code: public HttpResponseMessage Post([FromBody]dynamic result) { var localFilePath = graph ...

What is the best way to activate a component's function within a disabled tab using material-ui?

Currently, I am utilizing tabs from M-ui and encountered an issue when trying to incorporate a switch as one of the tabs. I made the tab non-clickable, but now the switch inside it is also not functioning. Below is the code snippet: https://codesandbox.i ...