The area available for clicking does not align correctly with the visible display of the div element

Is it possible to create clickable, animating sprites without relying on Flash? I want the sprites to show a bubble popup when clicked or touched, and then dismiss when the screen is clicked again. However, I'm facing an issue where the clickable areas do not align properly with the sprites.

You can view the webpage using Safari, Chrome, or the default browser for iOS or Android by following this link:

The clickable area for each sprite should be the same size as the sprite itself but centered on the corner from which the steam flows.

I have tested this functionality on various browsers such as Safari 6, iOS 6, Android 4.0's browser, and Chrome (version 21 on Windows 7). The issue persists across all these browsers.

If you have any suggestions on why the alignment is off or how to fix it, please let me know.

The relevant code can be found in index.html. Here are key excerpts:

<!doctype html>
<html>
    <head>
        <meta charset="utf-8">
        <title>CSS sprite demo</title>

        <style type="text/css">
            .spipe {
                position: absolute;

                width: 1px;
                height: 1px;

                background: url(spipe.png) no-repeat 0 0;
                background-size: 1px 20px;

                -webkit-animation-name: spipe;
                -webkit-animation-duration: 1.0s;
                -webkit-animation-iteration-count: infinite;
                -webkit-animation-timing-function: linear;
                -webkit-transform-origin: top left;
            }

            .left {
                -webkit-transform: scale(100, 60);
            }
        </style>
    </head>
    <body>
        <div id="toppipe" class="popup spipe left" style="top:120px;left:200px;" popupHTML="Hello, Top"></div>
    </body>
</html>

To prevent the sprite from rolling between frames, it needs to be scaled down and back up.

The problem seems to arise from the clickable area scaling up from a different origin than the rest of the div. Even changing the transform origin does not resolve the offset issue. Similarly, translating the div affects both the clickable area and the div, making it challenging to correct the alignment discrepancy.

Answer №1

Although not as tidy as I prefer, I discovered a method to achieve my desired outcome by incorporating some jQuery code:

$(function() {
    $(".target").each(function(index) {
        var original = $(this);
        var clone = original.clone();
        clone.insertAfter(original);
        original.removeAttr("id"); /* Ensure each id is only used once. */
        original.css("width","1px");
        original.css("height","1px");
        clone.attr("class","popup");
    });
});

Creating two overlapping divs for every div with the target class gives me the desired effect. One div contains the webkit CSS3 animation, while the other sits transparently on top and responds to clicks.

May seem convoluted, but it simplifies editing for anyone working on my page since they only need to adjust the HTML file without touching the CSS or scripts (which was my intention.)

Update: There was an issue where the misplaced image div sometimes blocked clicks to the clickable div. This was fixed by adding "pointer-events:none;" to the CSS.

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

Expanding Vue Tabs with Bootstrap: Manipulating tab-content to perfectly fill parent height

On my webpage, I have implemented a tabs component called b-tabs. This component is enclosed within a parent div with a specific height. I am trying to make the content of the tabs take up the full remaining height of the parent component. https://i.ssta ...

Conceal the Standard Select Dropdown Arrow in Internet Explorer 9

VIEW DEMO I attempted to use the CSS property appearance: none; to hide the select dropdown arrow, but it still shows in IE9. Refer to the image for clarification. Does anyone have a solution to hide the arrow using either CSS or jQuery? Below is my cod ...

Adjust ThreeJS camera zoom to match the size of a specific HTML element

I am currently diving into the world of Three.js and have stumbled upon an issue while trying to incorporate a plane geometry based on an image tag from the DOM. Situation Here is my current HTML template : <figure> <div class="aspect&quo ...

Designing a navigational sidebar featuring clickable links to specific locations on Google Maps

I'm currently utilizing a map script created by Derek Ender that integrates with Google Fusion Tables to display locations on a map. While the script is functioning well, I have received a request to make the sidebar list of locations clickable. The ...

Clicking the mouse will eliminate the input's focus

I have an input element with type radio. When the element receives focus via keyboard, it should display a focus style, but when accessed via mouse click, the focus should be removed. I want to achieve this without using JavaScript or jQuery. This element ...

What's the best way to arrange a series of images in a horizontal line using html and css?

Looking for a way to display a list of images in a straight line with just the right amount of spacing between them? Check out my fiddle and see the challenge I'm facing. https://i.sstatic.net/ZvICc.png I've been experimenting with HTML c ...

How to align li elements at center in a Bootstrap navbar

I'm having trouble centering link1 and link2 both horizontally and vertically on the page. The horizontal alignment is working fine, but I can't seem to get the vertical alignment right, no matter what I try. Here is the HTML code snippet: ...

Fixed footer positioned at the bottom of the page regardless of the amount of content present

I'm facing an issue where the footer is not sticking to the bottom of the page as intended. When there is less content, it should be displayed without any scroll, and if there is more content, the footer should appear at the end. Here is the code I am ...

Content of two li tags in row and column are not aligned properly

I am struggling with ensuring that the two columns and two rows of text in my page section are always aligned correctly. Column 1 and the contents of row 1 should be on the same line, but instead, column 2 is appearing a line or two below column 1. This is ...

What is the best way to choose the nearest element using the initial part of a class name?

I am working on a section of a table and need to hide a specific part when an icon is clicked. Below is the code snippet: <tr class="getmoreinfo_19"> <td>&nbsp;</td> <td colspan="3"> <div c ...

Issue with bottom margin on the last flex item located at the end of the container is not being applied

My button is currently touching the end of the container, but I want to create some space between them. However, adding a margin bottom to the button does not seem to be working as expected. Below is the CSS and HTML code: .events{ height: 100%; d ...

Avoid the ability for individuals to interact with the icon embedded within a button

I'm currently working on a website where users need to interact with a button to delete an "Infraction." The button has a basic bootstrap style and includes an icon for the delete action. <button referencedInfraction="<%= i.infractionID %>" ...

Expand the image background to fit within a div container

Below is the code snippet I am working on: <div id="intro_section_upper" > <%= image_tag("video_background.jpg", :id=>"video_bg") %> <div id="video_table_main" > <table class=" ...

When a user repeatedly clicks the "see more" button, they will continue to receive no results multiple times

I have created a partial view and added the rendering in the Index page. A button (See More) triggers an AJAX call to the controller each time it is clicked, appending new data to the screen. The issue arises when there are no results left to display, and ...

My navigation bar's CSS code falls short of extending across the full width of my screen, leaving a gap of approximately 10 pixels before reaching the edges

Can someone help me figure out what went wrong? I've been trying to remove the margins but it's not working. The background colors of other elements seem to be seeping into this empty space. Any thoughts or suggestions would be greatly appreciate ...

Facing difficulties in retrieving my static files with Express and Node.js

I'm puzzled as to why express isn't able to access my static file to display my CSS. Here is the code snippet from express.js: app.use(express.static(__dirname + '/public')); Contents of style.css: <style type="text/css"> bod ...

Step-by-step guide on creating a sequential glowing effect for list items with CSS and JQuery

I would like to create a glowing effect on each icon individually. The idea is for each icon to glow for a brief moment and then return to its normal state before moving on to the next icon in line. I am considering using text-shadow for the glow effect an ...

Assigning a modal value to an HTML field

I am in need of a solution for multiple HTML fields with a common modal attached to each one. The code I have currently looks like this: <!-- First Element --> <div class="box box-element ui-draggable"> <span class="config ...

Adjust and align image with an unknown dimensions

I need to adjust various images of unknown sizes (some bigger, some smaller) to fit inside a container of a known size while maintaining their aspect ratio. The goal is to stretch and center the images within the container. To clarify: If the images a ...

Android Gmail Application: Implementing 1px horizontal spacing between inline images placed within <td> tags

Have you ever noticed that in the Android Gmail app, there can be a mysterious 1px gap between inline images? This little pixel problem can sometimes push the rightmost image outside the comfy frame of your email. It seems this glitch prefers images of cer ...