Guide on incorporating a CSS animation at a particular spot within an image

I am faced with a dilemma involving two images. The first one will be used for my website, while the second one was manually created to identify fixed points. However, my issue lies in the fact that I am unsure how to incorporate my CSS animation into these specific locations.

I find myself at a standstill as the dots keeping changing positions based on screen or browser sizes. It is imperative that the design remains consistent across all browsers for a seamless user experience.

View the first picture https://i.sstatic.net/cuzxK.jpg

View the second picture (the targeted dot locations) https://i.sstatic.net/C41oZ.jpg

Here is the current code snippet:

<!DOCTYPE html>
<html>

<head>
  <meta charset="utf-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <title></title>
  <style>
    #bg {
      position: fixed;
      top: 0;
      left: 0;
      /* Preserve aspect ratio */
      width: 100%;
      height: 100%;
      object-fit: cover;
    }

  </style>
  <meta name="description" content="">
  <meta name="viewport" content="width=device-width">
</head>

<body>
  <img src="https://i.imgur.com/LpQXJfW.jpg" id="bg" alt="">
</body>

</html>

The pulsing dot animation:

<!DOCTYPE html>
<html>
    <head>
        <meta charset="utf-8">
        <meta http-equiv="X-UA-Compatible" content="IE=edge">
        <title></title>
        <meta name="description" content="">
        <meta name="viewport" content="width=device-width, initial-scale=1">
        <link rel="stylesheet" href="">
    </head>
    <style>
        * {
            box-sizing: border-box;
        }

        body {
            background-color: #cfd9df;
            margin: 0;
            height: 100vh;
            display: flex;
            align-items: center;
            justify-content: center;
        }

        .circle {
            background-color: rgba(255, 82, 82, 1);
            border-radius: 50%;
            animation: pulse-red 1.9s infinite;
            height: 25px;
            width: 25px;
        }


        @keyframes pulse-red {
            0% {
                transform: scale(0.9);
                box-shadow: 0 0 0 0 rgba(255, 82, 82, 1);
            }
            
            80% {
                transform: scale(1);
                box-shadow: 0 0 0 11px rgba(255, 82, 82, 0);
            }
            
            100% {
                transform: scale(0.9);
                box-shadow: 0 0 0 0 rgba(255, 82, 82, 0);
            }
        }
    </style>
    <body>
        <div class="circle"></div>
    </body>
</html>

My ultimate goal comprises the skeleton presented above. Subsequently, an attempt was made illustrating my intended purpose. Unfortunately, it lacks responsiveness and necessitates manual handling of point placement.

function placeDiv(x_pos, y_pos) {
  var d = document.querySelector('.circle');
  d.style.position = "absolute";
  d.style.left = x_pos + 'px';
  d.style.top = y_pos + 'px';
}

window.addEventListener("click", function(e) {
  placeDiv(e.clientX, e.clientY);
});
#bg {
  position: fixed;
  top: 0;
  left: 0;
  /* Preserve aspect ratio */
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.circle {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  background-color: rgba(255, 82, 82, 1);
  border-radius: 50%;
  animation: pulse-red 1.9s infinite;
  height: 25px;
  width: 25px;
}

@keyframes pulse-red {
  0% {
    transform: scale(0.9) translate(-50%, -50%);
    box-shadow: 0 0 0 0 rgba(255, 82, 82, 1);
  }
  80% {
    transform: scale(1) translate(-50%, -50%);
    box-shadow: 0 0 0 11px rgba(255, 82, 82, 0);
  }
  100% {
    transform: scale(0.9) translate(-50%, -50%);
    box-shadow: 0 0 0 0 rgba(255, 82, 82, 0);
  }
}
<body>
  <img src="https://i.imgur.com/52dLf1W.jpg" id="bg" alt="">
  <div class="circle"></div>
</body>

How can I seamlessly integrate four pulsing animations onto my image to maintain uniformity across all screen sizes?

Answer №1

To make this concept effective, maintaining the aspect ratio of the image is crucial. Alternatively, you could convert it to base64 and highlight specific areas pixel by pixel.

Give this a try!

const imageBG = document.getElementById("bg");
const container = document.getElementById("container");
const imageBGBounds = imageBG.getBoundingClientRect();
const circle = document.getElementById("circle")
const circleBounds = circle.getBoundingClientRect();
window.onload = function() { sizeImage() }
window.addEventListener("resize", () => { sizeImage() });
  
function sizeImage() {
  const imageBGBounds = imageBG.getBoundingClientRect();
  const circleBounds = circle.getBoundingClientRect();
  const ratio = 320/853;
  const width = window.innerWidth;
  const height = width * ratio;
  imageBG.style.width = width+'px';
  container.style.width = width+'px';
  imageBG.style.height = height+"px";
  container.style.height = height+"px";
};
* {
  box-sizing: border-box;
}

body {
  background-color: #cfd9df;
  margin: 0;
}
#container {
  position: relative;
 /* width: $width;
  height: $height;*/
}
#bg {
  position: absolute;
 /* width: $width;
  height: $height;*/
}
#circle {
  position: absolute;
  left: 60%;
  top: 60%;
  background-color: rgba(255, 82, 82, 1);
  border-radius: 50%;
  animation: pulse-red 1.9s infinite;
  height: 25px;
  width: 25px;
  z-index: 1;
}

@keyframes pulse-red {
  0% {
    transform: scale(0.9);
    box-shadow: 0 0 0 0 rgba(255, 82, 82, 1);
  }

  80% {
    transform: scale(1);
    box-shadow: 0 0 0 11px rgba(255, 82, 82, 0);
  }

  100% {
    transform: scale(0.9);
    box-shadow: 0 0 0 0 rgba(255, 82, 82, 0);
  }
}
<div id="container">
<img src="https://i.imgur.com/LpQXJfW.jpg" id="bg" alt="">
<div id="circle"></div>
</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

Error message: The desired element is not found in the cache when selecting a radio button with mechanize::phantomjs

Currently, I am working on automating a webpage that contains numerous JavaScript functions using Perl. I have been successful in utilizing the headless mechanize::phantomjs toolkit thus far. However, I have encountered what seems to be a minor issue that ...

what is the smallest browser width required to show the navigation bar collapse button?

Is it possible to adjust the browser width in order to display the collapse button for a navigation bar in Bootstrap? I believe media queries could assist with this, but I am unsure how to specify the minimum width of the browser window. ...

Sorting dates in Mongoose's aggregation feature is not functioning properly

Could someone please explain why the results of this aggregation query are not being sorted by the created_at date? User.aggregate([ // Filtering for records created within the last 30 days { $match: { "created_at":{ $gt: new Date(today.getTime() - ...

Encountering a ReferenceError while debugging MongoDB: The console object is undefined

Using a js file within mongodb, I implemented a code snippet containing a console.log expression for debugging purposes: use test; db.city.find().snapshot().forEach(function(city){ var Pos = city.Pos; if (Pos) { longLat = Pos.split(" ...

Determining the starting and ending position of text within an element using jQuery

Delving into the world of jQuery/JS has been both challenging and exciting for me. However, I've encountered a problem that's got me stumped. Here is a snippet of text that I need to work with: blablablabla <b data-start="" data-end="">#fo ...

Discover a multitude of items simultaneously using mongoose

I am trying to find multiple objects in a mongo model with different properties simultaneously. model.find({uuid: 235q422462}, {uuid: 435q4235239}, function(err, objects){ if(err){ console.log(err) } else { console.log(objects) ...

Mastering the Art of Manipulating Dropdown Select Options Menu Using Jquery

I am currently working on a website project that involves a form where users input details. Within this form, I have included two dropdown menus. My goal is to disable the children menu when the user selects number 9 from the Adults dropdown, while allowin ...

Updating the image source with a span tag: A step-by-step guide

I am attempting to update the img src value by utilizing the data from the span tag Although I have successfully retrieved the value for the span tag, I am struggling to find a method to change the img src value The issue lies in the fact that the span tag ...

The CSS property overflow-x:hidden; is not functioning properly on mobile devices despite trying multiple solutions recommended online

Seeking help on a persistent issue, but previous solutions haven't worked for me. Looking to implement a hamburger menu that transitions in from offscreen. The design appears correctly on desktop and simulating mobile, but actual mobile view require ...

Can anyone provide a solution to modifying the default browser action when clicking on hashtags?

Imagine a scenario where the code snippet below is present: <a name='test'></a> Now, when this code is loaded in a browser and #test is appended to the URL, the browser automatically scrolls so that the <a> element appears at ...

When it comes to TypeScript, there is a limitation in assigning a value to an object key with type narrowing through the

I created a function called `hasOwnProperty` with type narrowing: function hasOwnProperty< Obj extends Record<string, any>, Prop extends PropertyKey, >( obj: Obj, prop: Prop, ): obj is Obj & Record<Prop, any> { return Object ...

Discover the perfect method for combining two objects while updating any empty values with a new specified value. Furthermore, in the case where the new value is also

My task involves working with an array of objects where each time I select a value, it gets pushed into the array. My goal is to merge two objects that share the same key "code" and remove any empty values. (4) [{…}, {…}, {…}, {…}] 0: {code: "abc ...

Integrating Query String Parameters into GridView Item Templates

Within my gridview, I have a hyperlink located in the first column. When this hyperlink is clicked, the user is directed to Vendor.aspx. I now need to pass the consumer ID (from the clicked row) as a query string to Vendor.aspx. What is the most effective ...

Display additional information from a JSON file after choosing an ID with AngularJS Select

After saving a JSON file filled with information, I managed to successfully populate a select menu with the names of each element from the JSON data using this code snippet: <select ng-model="car.marca" ng-options="item.brakeId as item.name for item in ...

Arrange two columns of input fields vertically, one column with labels and the other without any labels

I am currently working on an application form for invoices, where I have set up five columns in one row. Each column contains input fields, with the fourth and fifth columns having four input fields each. However, the input fields in the fifth column do no ...

Enhance Your Three.js Experience: Implementing Dots on Vertices

I am working with a wireframe sphere and looking to add dots to the vertices. Something similar to this image: https://i.sstatic.net/pzNO8.jpg. Below is all of my JavaScript code: var scene = new THREE.Scene(); var camera = new THREE.PerspectiveCamera( ...

Ways to stop Content from Showing below a div container

Hey, I just created a login panel using CSS and HTML. After applying some floats, all the content ended up displaying under the panel. I attempted to use clear: both, but that didn't resolve the issue. My goal is to have all other contents displayed a ...

What is the time stamp format of 1651928421543667000?

Recently, I have encountered an issue with an API returning a timestamp as 1651928421543667000. Despite trying various PHP functions like strtotime(), datetime(), and strftime(), I am unable to find the correct format for it. Can anyone provide some guid ...

Is it possible to send a ternary expression inside a component as a prop based on whether the condition is true or false?

Is it possible to include a ternary expression inside a component and pass it as a prop depending on whether the condition is true or false? <ExperienceList onUserToggle={this.onUserToggle} jobs={this.state.jobs[this.state.value]} { th ...

What is the approach for capturing system or website sound using JavaScript?

After creating an online drumkit and guitar player, I am now looking to enhance my website by adding a feature that allows users to record their sessions and download them. Since I am new to web development and familiar only with HTML, CSS, JavaScript, and ...