jQuery Bug: Issue with Creating and Destroying Multiple Divs

I've come across a strange issue involving CSS3/HTML5/Javascript on Webkit browsers (have not tested on others).

Check out this fiddle and see for yourself: http://jsfiddle.net/tbergeron/XHQxH/

If you hover over multiple "tiles" quickly, you'll notice that sometimes it stops working.

The javascript code in question is:

 $('.tile').one("transitionend webkitTransitionEnd oTransitionEnd MSTransitionEnd", function() {
    var tile = this;

    // Hide Title label
    $(tile).find('.title').hide();

    var bigTileHtml = '<div class="bigTile">';
    bigTileHtml = bigTileHtml + '<div class="title">Tile Title Holy Cow Yeah</div>';
    bigTileHtml = bigTileHtml + '<div class="description">Tile description goes here.</div>';
    bigTileHtml = bigTileHtml + '</div>';

    // Create a new bigTile
    var bigTile = $(bigTileHtml).appendTo('.tiles');

    // Sets bigTile's position
    var position = $(this).position();
    bigTile.css('top', position.top + 4);
    bigTile.css('left', position.left + 4);

    bigTile.mouseout(function() {
        // Show Title label
        $(tile).find('.title').show();
        bigTile.remove();
    });

    bigTile.show();
});

You can view the HTML/CSS details in the fiddle provided above.

EDIT: The issue appears to be that the "webkitTransitionEnd" event only fires once. Is there a way to reset this behavior so that it can be fired again after each transition ends?

In short, when hovering over tiles multiple times, the pink div may stop displaying.

Thank you to anyone who can offer assistance.

/tommy

Answer №1

The pink div only appears one time as your function is called just once for each tile. This is due to the use of the one() event handler.

The code accomplishes the following:

  • When hovering over a tile, a CSS animation is triggered
  • After the animation completes, the event listener function is activated (but only for the first instance of the animation finishing on each tile)
  • The event listener function generates the pink tile and assigns an event listener to this new tile that activates when the cursor exits the tile
  • Upon activation, the pink tile is removed

All these functionalities can be achieved solely with CSS3. I have made changes to your jsfiddle code to demonstrate how this can be done using CSS3 with hover effects and transitions. If desired, some JavaScript can be incorporated to dynamically update the hover tile's content, like in this updated version:
http://jsfiddle.net/XHQxH/9/

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

Removing embedded documents over time - MongoDB and Node.js

While exploring MongoDB's TTL feature, I discovered that it only works on entire documents. My goal is to automatically delete user notifications after a certain period (2 weeks) on my Node.js server. The notifications are stored as an array of object ...

Error occurs when attempting to access second level route in Vue directly

I am currently utilizing vue-router within my vue application. The application consists of the following routes: const routes = [ {name: "home", path: "/", component: Home}, {name: "user", path: "/user", component: User}, {name: "edit-user", p ...

how can I retrieve an element using a datetime in JavaScript

I have a list of appointments like the one below: 0: {start: '2022-02-23T09:30:00', end: '2022-02-23T10:00:00',…} 1: {start: '2022-02-23T10:00:00', end: '2022-02-23T10:30:00',…} 2: {start: '2022-02-2 ...

Performing a subselect in an SQL SELECT statement using Node.js

Hello there! I am currently working on a node.js application that involves working with a table structure stored in my MySql database: https://i.sstatic.net/DqeQ9.png My current task is to retrieve the names from table_4 and their corresponding names fr ...

Convert this JavaScript function into a jQuery function

I currently have this JavaScript function: function removeStyle(parent){ var rmStyle = document.getElementById(parent).getElementsByTagName("a"); for (i=0; i<rmStyle.length; i++){ rmStyle[i].className = ""; } } Since I am now using ...

A step-by-step guide on shifting an image to the left and revealing text with a button press

I recently started experimenting with web design. I managed to center an image, add a button below it, and create a toggle effect where clicking the button displays text beneath the image. Clicking the button again hides the text, returning to the initial ...

Looking to center a title in React Navigation without interference from headerLeft?

I am using react navigation and trying to center the title in the header bar. However, it seems to be affected by the presence of headerLeft. When I disable headerLeft, the title centers perfectly. How can I achieve this without interference from other lef ...

Guide to modifying the text color of a Primefaces/jqPlot line chart:

I've implemented a basic JSF line chart with PrimeFaces (using jqPlot library) in my project: <p:lineChart id="linear" value="#{team.chart}" title="Lap Times" xaxisLabel="Lap" yaxisLabel="Time ...

JSX conditional rendering not behaving unexpectedly

Having difficulty with a conditional JSX statement causing an element to not display properly unless the window is resized. Please note that it works fine in development mode but does not show correctly after building. The goal is to show navigation links ...

Recommendation: 3 options for radio buttons on the registration form

My form includes a section where users need to choose if they want to sign up for a session that occurs 3 times daily. The catch is, only 5 applicants can enroll in each session (AM, Mid-day, PM). It's a competition to secure a spot. Here is the form ...

Unable to locate a declaration file for the module "../constants/links" in src/constants/links.js, as it implicitly defaults to type 'any'

Within my VueJS application, I have brought in some constant variables. <script lang="ts"> import { Component, Prop, Vue } from 'vue-property-decorator' import { MOON_HOLDINGS_LINK, TWITTER_LINK } from '../constants/links' @Comp ...

Transfer content between two textareas using Ajax with a post request

Attempting to utilize ajax for posting text from one textarea to a php page and then displaying it back in another textarea. Surprisingly, the process seems to work fine with just 5 characters but completely stops afterward. Tried encoding and non-encoding ...

Using JQuery to eliminate the current div in an image slider

I currently have an image slider that allows users to switch between images. There are two buttons - one adds a new item to the slider, while the other is supposed to remove the current image from the slider, but it doesn't seem to be working properly ...

The absence of a backslash in the JSON string is noticed upon uploading it to the database

After using the JSON.stringify() method in JavaScript to convert my JSON object into a JSON string, I insert it into a database via AJAX posting to a PHP file. $("#saveToDatabase").click(function(){ var place = searchBox.getPlaces(); var locati ...

What is the best way to eliminate the gaps between elements in HTML?

Is there a way to reduce the space between the strings "Text 1" and "its simple" to just 10 pixels using margin-top: 10px;? When I apply margin-top: 10px;, the total space seems to be more than just 10 pixels due to shifting. In my understanding, the whit ...

What might be causing my dropdown menu to be unresponsive in HTML?

In this HTML code, I opted to use images as dropdown elements instead of traditional buttons or text. /* Dropdown Button / .dropbtn { background-image: url(Images/Buttons/Resources3.png); width: 110px; height: 40px; } / The container <div> - neede ...

Confirming the presence of values following hyphens in a string

Can you help me with this? I want to create a function that checks if the string below (represented by var x) has values after each of the 7 dashes and returns valid or invalid var x = 4-D-5240-P43-120-08A2-8123-0000 (valid) Here are some examples where ...

Tips for sending multi-dimensional arrays in an HTML form via request?

I have created a form where users can select products and enter the quantity for each product. Here is the structure of my form: <select name="products[][product_id]"> @foreach($products as $product) <option value="{{ $ ...

List items are loaded dynamically in an unordered fashion

I have been working on a jquery slider using flickerplate. Below is the code that works when the values are hardcoded: <div class="flicker-example"> <ul> <li data-background="lib/flicker-1.jpg"> <div class ...

Alert when every ajax call is completed

Here is some code I have written: var chapterNameArr = ['firstchapter','secondchapter','thirdchapter','fourthchapter','fifthchapter','sixthchapter','seventhchapter']; $.each(chapterN ...