How to animate SVG element transformations (rotation & scaling) on Internet Explorer

My SVG element, an arrow spinning around a circle with scale animation using transform and transition properties, works smoothly in the latest versions of Chrome, Opera, and Firefox. However, in Internet Explorer, the animation does not occur as expected because the SVG element requires the use of the transform attribute instead of CSS transformation.

Although I have tried to apply the same transform to the attribute dynamically in my script, the animation still "skips" to the final position without transitioning. You can see a demonstration of this issue on JSFiddle: https://jsfiddle.net/rv28ezfw/3/

I am now seeking a solution or plugin that can handle animation in IE without affecting the functionality in other browsers. One option I came across is the jQuery SVG plugin by Keith Wood and a demo on CSS-Tricks.com that addresses SVG transforms in IE as well. While I prefer a simpler solution, I am open to recommendations for either of these approaches.

Answer №1

I couldn't pinpoint the issue causing it to malfunction in IE11. However, I devised a workaround:

$('#btn').click(function() {
  // Altered for smoother demo.
  $('#container').toggleClass('rotated');
});
#container {
  /* Adjusted size for better snippet appearance */
  width: 300px;
  height: 300px;
  /* For visibility */
  border: 1px solid black;
  /* Made transparent to prevent overlap with other elements */
  background: rgba(0,0,0,0);
  /* Allows events to pass through */
  pointer-events: none;
  /* Transition effect moved from SVG */
  transition: all 1.5s ease;
}
/* New addition */
#container.rotated {
  transform: rotate(45deg);
}

#btn {
  padding: 10px;
  color: #fff;
  text-align: center;
  background: green;
}

.cls-1 {
  fill: #2bffaa;
}

.cls-2 {
  fill: #ccc;
}

.cls-3 {
  fill: #f2f2f2;
}

.cls-4 {
  fill: #ddd;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div id="btn">GO</div>
<div id="container">
  <svg id="scroller" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 480 480">
    <title>demo</title>
    <path id="scroller__outer" class="cls-1" d="M240,147a92.93,92.93,0,0,0-28.29,4.39l5.14,12A80.1,80.1,0,1,1,179.23,188L132.31,226.4c13.11,3.06,15.18,4.06,15.18,4.06S147,236.78,147,240A93,93,0,1,0,240,147Z" />
    <path id="scroller__inner" class="cls-2" d="M240,158a84.78,84.78,0,0,0-23.82,3.86l1.76,4.13,6.59,15,0.68,1.44A59.46,59.46,0,1,1,190.56,207l-0.92-1.44-9.17-15.41L179.23,188c-12,14-21.22,32.14-21.22,52,0,44.18,37.82,82,82,82s82-37.82,82-82S284.18,158,240,158Z"
    />
    <circle id="scroll__inner__circle" class="cls-3" cx="240" cy="240" r="51.5" />
    <path id="scroll__inner__outline" class="cls-4" d="M240,179a61,61,0,1,0,61,61A61,61,0,0,0,240,179Zm0,117a56,56,0,1,1,56-56A56,56,0,0,1,240,296Z" />
  </svg>
</div>

In summary, I opted to rotate #container instead of the SVG itself. Then, I transferred the transforms to #container.

By rotating a div, there's a possibility of corners overlapping underlying elements. In this demonstration, I made it translucent but outlined the borders for visibility. With pointer-events: none, users can still interact with the "GO" button even if a corner of the div overlaps it.

You could also adjust your SVG layout to reduce the excess white space surrounding the icon.

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

Is it possible to incorporate a CSS3 transition into the styling of a list of images?

Looking to achieve a CSS3 linear transition for a "list-style-image" specifically for Firefox? You'll need to include "-moz-" in your code. -moz-transition: list-style-image 0.2s linear; However, the above code is not producing the desired result. I ...

Using TypeScript to pass an array list as a parameter in the HTTP native GET method

Attempting to send an array list parameter. The codeList parameter contains an array like this: [ { "projCode": "11-1115", "cblTagNo": "571_GE001-RC1" }, { "projCode": "11-1115", "cblTagNo": "571_GE001-S" } ] Encountering the erro ...

Include the image source in the array

Currently, I am utilizing this loop to showcase images using Smarty {foreach from=$gallery item=image key=KEY} <div class="col-lg-2 col-md-2 col-sm-4 col-xs-6 smallImage"> <img ng-click="bigImage('/files/galleries/{$image.gallery ...

Eliminate extraneous space with the clearfix:after pseudo-element

Could use some help figuring out how to remove the unwanted whitespace caused by clearing the float (specifically after the tabs). Any suggestions on how to fix this issue? Take a look at the code snippet below (jsfiddle): /* Clearfix */ .clearfix:af ...

Tips on changing an image with a button click

I am currently working on a project where I have a div tag containing an image that is selected randomly from different arrays based on topics. However, I am facing some challenges in making the image change when the "go" button is clicked. I want the if ...

The Power of Ajax in PDF Retrieval

At my workplace, we have an innovative approach to ajax using a custom in-house framework. Essentially, within a JavaScript function, I use the following code: CT.postSynch('report/index/downloadProjectsInProgress', {}, function(data){ } ...

Methods for invoking a function from a separate .js file within React Native Expo

I'm new to using React and I've come across a challenge: In my Main.js file, there is a button: import * as React from 'react'; import { StyleSheet, Text, View, SafeAreaView, Pressable, Alert } from 'react-native'; import { M ...

Electron framework experiencing compatibility issues with JQuery

I am currently attempting to integrate jQuery with the electron framework using electron fiddle. However, it seems that jQuery is not functioning correctly and animations are not being executed. For reference, you can check out the example: https://www.w3s ...

Shifting an HTML anchor to account for a stationary header - Safari compatibility with alternative CSS styling

I made adjustments to my HTML anchors by adding an offset in the CSS to accommodate for a fixed header in my theme: margin-top: -175px; padding-top: 175px; } /* Adjustments for screen sizes of 760px and smaller */ @media (max-width:760px){ #r ...

date-fns | display date

Issue I have a function that formats date strings as shown below. import { format, parseISO } from "date-fns"; export function convertDate(myDate, displayFormat) { return format(new Date(parseISO(myDate)), displayFormat); } My articles con ...

Unusual Type Inference in Typescript {} when Evaluating Null or Undefined

Upon upgrading from typescript 4.9.3 to 5.0.2, we encountered an error when asserting types. Can someone explain why the function "wontWorking" is not functioning correctly? I expected this function to infer v as Record<string, any>, but instead it ...

Issues with the inline display of dropdown list and label in Asp.Net

I am currently having an issue with an asp.net dropdown list that has a css class with the following markup: .form-control { display: block; width: 100%; height: 34px; padding: 6px 12px; font-size: 14px; line-height: 1. ...

The browser fails to render an EJS-generated page when responding to a Fetch request

Today, I encountered a strange issue that has left me puzzled. In summary, I have been sending a PUT request from a user form to the backend. Since forms do not natively support PUT/DELETE requests, I had to use a script to handle this task for me. let for ...

The DataTable fails to refresh following modifications to the HTML table

After making changes to a table row using basic JavaScript, the datatable is not updating properly. Despite seeing the updated values in the table view, retrieving data from the datatable shows the old values. Below is the structure of my table: <tab ...

Using Select2 JS to populate dropdown options with an AJAX response

I have a large list of pincodes ranging from 20,000 to 25,000. I want the user to search for the first 3 digits of a pincode and then trigger an ajax request to fetch a list of pincodes that match those 3 digits. Although I am successfully receiving a res ...

Utilize jQuery to bind JSON data to a form before sending it off

If I have an empty form like this, what would be the jQuery code to add a JSON object as parameters and then submit it in a standard form submission manner (not using AJAX)? <form action="/comments" method="post" id="comments_form"> <submit& ...

Organize and display a list of contacts alphabetically by the first letter of their

I have a list of contacts that I need help with. Despite searching on Stack Overflow, I couldn't find the answer. Can someone please assist? Thank you. export const rows = [ { id: 1, name: 'Snow', email: 'Jon', co ...

What could be causing the JSON String decode error to occur while utilizing extjs ajax?

Here is an example of my code: Ext.Ajax.request({ url:'test.jsp', params:{id:id,password:password}, success:function(response){ console.log(response); var results = Ext.util.J ...

The leave animation for Angular's ngAnimate and ng-view feature appears to be malfunctioning

angular version: 1.6.1 I am attempting to create a fade in/out effect for my ng-view element, however, I am encountering an issue where only the enter animation is functioning properly. This is the relevant HTML code: <main class="main" ng-view>&l ...

Maximizing Efficiency of Vendor Bundle in Angular 2 with Webpack

My MEAN application's client side is built in Angular2 with Webpack, but I'm facing slow loading times due to a large vendor modules JS file. Is there a way to optimize this situation? I want to separate the vendor's JS file. Below is my we ...