Rhythmic foliage icon created with dynamic CSS3 animations

I am looking to develop a unique animated map marker icon for my Leaflet map without relying on third-party plugins to enhance my learning experience.

My current approach involves using CSS to create a 'pulsating' animation effect:

.gps_ring {
    border: 3px solid #999;
    -webkit-border-radius: 30px;
    height: 18px;
    width: 18px;    
    -webkit-animation: pulsate 1s ease-out;
    -webkit-animation-iteration-count: infinite;     
}   
@-webkit-keyframes pulsate {
    0% {-webkit-transform: scale(0.1, 0.1); opacity: 0.0;}
    50% {opacity: 1.0;}
    100% {-webkit-transform: scale(1.2, 1.2); opacity: 0.0;}
}

To implement this custom marker, I am utilizing Leaflet's DivIcon and referencing the CSS class mentioned above:

// Define an icon called cssIcon
var cssIcon = L.divIcon({
    // Specify a class name we can refer to in CSS.
    className: 'gps_ring'
});

// Create markers and set their icons to cssIcon
L.marker([50.5, 30.5], {icon: cssIcon}).addTo(map);

However, I am experiencing issues with this setup as the animated marker icon consistently appears in the top left corner of the map. It seems that the scaling transformation is interfering with the marker's correct positioning:

https://i.sstatic.net/u0xbN.png

For reference, I am running Chrome 44.x on Windows 7 and Yosemite operating systems.

I have prepared a simplified demonstration which can be accessed here:

http://jsfiddle.net/christianjunk/q69qx45c/1/

What could be causing this issue? Why is the animation disrupting the marker's position on the map?

Answer №1

After spending some extra time investigating, I stumbled upon a solution:

I made a slight modification to the CSS code:

.css-icon {

}

.gps_ring { 
    border: 3px solid #999;
     -webkit-border-radius: 30px;
     height: 18px;
     width: 18px;       
    -webkit-animation: pulsate 1s ease-out;
    -webkit-animation-iteration-count: infinite; 
    /*opacity: 0.0*/
}

@-webkit-keyframes pulsate {
        0% {-webkit-transform: scale(0.1, 0.1); opacity: 0.0;}
        50% {opacity: 1.0;}
        100% {-webkit-transform: scale(1.2, 1.2); opacity: 0.0;}
}

Additionally, I made adjustments to the instantiation of my DivIcon class:

// Defining an icon called cssIcon
var cssIcon = L.divIcon({
  // Setting a class name for CSS reference.
  className: 'css-icon',
  html: '<div class="gps_ring"></div>'
  // Setting marker width and height
  ,iconSize: [22,22]
  // ,iconAnchor: [11,11]
});

The key was utilizing the inner HTML to execute the CSS animation, ensuring that the marker's position remains intact. Also, take note of the iconSize attribute which reflects the final size of the icon after transformation (21 px =~ 18px x 1.2). By setting it this way, the animated circle is centered at the specified coordinate:

See the working example here: http://jsfiddle.net/christianjunk/waturuoz/

https://i.sstatic.net/zniDu.gif

I still haven't quite figured out why my initial approach didn't work as expected.

Answer №2

The reason your initial method failed is due to the utilization of transform, a property also employed by Leaflet to position its markers.

Here's an illustration of how a Leaflet placement can be superseded:

transform: translate3d(499px, 604px, 0px);

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

A function that recursively calls itself and uses a promise for iteration

In my current setup, I have a function called emailIterator that reads messages from a stack and sends them one by one using an emailer. The process is done recursively by calling emailIterator with fewer messages each time as they are sent. import { ema ...

What is the best way to create space between table rows without using border-spacing?

I've been attempting to use the margin-bottom property on my table in order to separate the rows, but it doesn't seem to have any effect. I then tried using flex, which did work, but the table rows did not inherit the width and I had to specify a ...

Padding on the left and right in Bootstrap

Here is the code snippet I'm working with: <div class="col-md-12 pt-5 let-top"> <h1>A</h1> </div> For small and extra small screens, I am looking to include padding on both the left and right sides. Can anyone help me wit ...

Identify the index of a list item using a custom list created from buttons

When dealing with a dynamically built list like this: <ul id="shortcuts"> <li><input type="checkbox" value="false"/><button>foo</button><button>-</button></li> <li><input type="checkbox" value ...

The correct functioning of CSS hyperlinks is currently experiencing issues

The links in the "request" division are not displaying properly. The style.css file contains the following code for the links in this division: .header .request a span{border-bottom:1px dotted}.header .request a:hover span{border-bottom:0} Example: berdy ...

What's the easiest method for moving div content from side to side?

Working on a plugin for WordPress, I am faced with the task of moving content in a slider from left to right and right to left. My current attempt is as follows: var effect = 'slide'; // Set the options for the chosen effect type var opti ...

A step-by-step guide on incorporating RAW css into your Jekyll website

I am experiencing an issue with loading a CSS file on my website. <link rel="stylesheet" href="/assets/css/my_file.css"> This file is located at _assets/css/my_file.css. However, when I try to load the page, the CSS file does no ...

Exploring ways to store dat.gui parameter to the backend in a Django and Three.js environment

In my project, I am utilizing Django as the backend framework and model.form for data storage. Additionally, I have integrated dat.gui with a three.js scene. My query revolves around the process of saving dat.gui parameters to Django. (specifically how t ...

Retrieving image from a URL using JavaScript

I am attempting to display an image on my webpage from a different URL. <body> <div id="container"> <br /> <canvas width="500px" height="375px" id="canvas"> </canvas> <img src="http://yinoneliraz-001-sit ...

How can you resolve the issue of unnecessary right scrolling by 5 pixels?

Is there a reason why the page is scrolling right to left unnecessarily? Here's the current code on Codepen for reference - some adjustments had to be made to the body margin and padding to avoid a gap between the footer and the end of the page. Vie ...

Differences between using Constructor(props) and super(props) versus simply using constructor() and super() in React Development

Although this question has been asked numerous times, it still remains unclear to me. Many have simply stated: Pass props to constructor if you want to access this.props there Here is another example of the answer The official documentation states tha ...

Remove all HTML tags and double quotation marks from the text

Looking to tidy up my entries resembling If you think adventure is dangerous, try routine; it is lethal. <p>Life isn't about finding yourself it's about creating yourself. </p> Task at hand involves eliminating HTML tags, double quo ...

Keys that are able to change dynamically

I am attempting to generate a dynamic object with dynamic keys like so: var test = "test"; var obj = { test:"bananas" } However, I am encountering an error: Uncaught SyntaxError: Unexpected token + Is this prohibited? Is there any way to accomplish t ...

Troubleshooting problems with timezones in Mongodb when filtering records based on

My goal is to retrieve all records with a "date" field falling between the startDate and endDate parameters. Here is the query I am using to fetch records from the beginning of the month up to today: var startDate = new Date(2017, 09, 1); var endDa ...

Tips for preventing vertical spaces between table header cells in material-UI

Is there a way to remove the vertical gaps between header cells in the MUI table? To see an example of the issue, check out this codesandbox link: https://codesandbox.io/s/mui-material-table-sticky-header-forked-euilo3?file=/tsconfig.json I have attempte ...

Tips on Including a Custom Header in an Ajax Request for a Cross-Domain JsonP Call

Is there a way to add a custom header using an ajax call in jQuery for a cross-domain JSONP call? I am making a web service call in an HTML page using Ajax cross-domain call. I am currently using JSONP and now need to send some parameters in the header. ...

Can you provide me with advice on how to make a materialize table responsive?

Here is the script I am using: <table class="responsive-table"> <thead> <tr> <th>Mon</th> <th>Tue</th> <th>Wed</th> <th>Thr</th> <th>Fri& ...

Get the nearest offspring of the guardian

I have a main 'container' div with multiple subsections. Each subsection contains 1 or 2 sub-subsections. Let's say I have a variable that holds one of the subsections, specifically the 4th subsection. This is the structure:container > s ...

Replace the value within an array

Is there a smart method for substituting or replacing a value within an array? For example: var array = [[1,2,3,'null'],['null',2,3,4],['null','null','null','null'],[1,1,1,1]] The desired outpu ...

The link in the navbar isn't functioning properly, which indicates that it's not redirecting to the specified ID on this one-page application

<!-- NAVBAR --> <nav class="navbar navbar-expand-lg py-3 sticky-top navbar-light bg-white"> <div class="container-fluid"> <a class="navbar-brand" href="#acasa"> <img class="logo" src="./assets/img/xxxxx_psiholog_logo. ...