Issue with Hover Persisting despite Sortable Plugin Usage

I wrote a script that works perfectly in Chrome, but I'm running into issues with IE8:

Here is my jQuery code:

$("<div class='divButtons'></div>").appendTo( $(".widget_header") );
$(".divButtons").text("321");

This is the CSS I'm using:

.divButtons { background:orange; display:none; }
.widget:hover .divButtons { display:block; }

Check out my jsFiddle for the full demonstration:

Click here to view the jsFiddle.

What's working:

Currently, when I hover over a .widget, the .divButtons appears due to the CSS styling. Moving one widget to another keeps everything functioning smoothly as intended. However, in IE8, there's a problem not present in Chrome.

The issue:

In IE8, when I hover over a .widget and then move it to a different part of the screen before releasing it, the .divButtons continues to display on the initial .widget even though I'm no longer hovering over it. This discrepancy doesn't occur in Chrome.

Seeking solution:

Is there a way to ensure this functionality behaves correctly in IE8, similar to how it does in Chrome?

Answer №1

There appears to be a bug in IE8 where the mouseout or mouseleave events are not triggered when an element is moved away from under the mouse cursor. This results in the :hover state not being removed and prevents event listeners for mouseout, hoverleave, etc in jQuery from being called.

To address this issue, I have implemented a solution that checks if any .column element is being hovered over when a .widget is released. If no columns are detected as being hovered, the hover state is removed from the widget.

A .hover class is applied to the .widget element to manage this workaround since removing the :hover state directly using jQuery is not feasible.

jsFiddle Demo:

For a demonstration of the fix in action, you can visit this jsFiddle link.

CSS Code:

.widget.hover .divButtons { display:block; }

jQuery Code:

// Handling hover states for columns
$('.column').hover(function() {
    $(this).addClass('hover');
}, function() {
    $(this).removeClass('hover');
});

// Controlling hover behavior for widgets
$('.widget').hover(function() {
    $('.widget.hover').removeClass('hover');
    $(this).addClass('hover');
}, function() {
    $(this).removeClass('hover');
});

jQuery Sortable Implementation:

$( ".column" ).sortable({
    connectWith: ".column",
    tolerance: 'pointer',
    // Executing code on widget drop event
    stop: function(event, ui) {
        // Delay execution by 1 millisecond after widget drop
        setTimeout(function() {
            // Checking if any widget is currently hovered
            if ($('.widget.hover').size() > 0) {
                // Removing hover class if parent column is not hovered
                if (!$('.widget.hover').first().parent().is('.hover')) {
                    $('.widget.hover').removeClass('hover');
                }
            }
        }, 1);
    }
});

I trust this solution will be effective for your needs.

It's frustrating that even in 2012, we still encounter such challenges due to bugs in older versions of Internet Explorer.

Answer №2

Would you consider using the hover pseudo-class instead of this alternative?

CSS

.widget.hover  .divButtons { display:block; }​

JS

$('.widget').hover(function(e){
    $(e.currentTarget).addClass('hover');
},function(e){
    $(e.currentTarget).removeClass('hover');
});

Answer №3

Encountering a similar issue with IE9 where it tends to get stuck in a hover state if the DOM element is changed before mouseout occurs.

Without finding a concrete solution for this behavior, I decided to use jQuery's .hover() method instead of the :hover pseudoclass, as shown here:

$(elt).hover(function () {
    $(this).addClass("jHover");
}, function () {
    $(this).removeClass("jHover");
});

Although not as flashy, it proves to be more reliable in handling the issue.

Answer №4

When it comes to applying hover styles, Internet Explorer can be a bit unreliable, especially on elements other than anchors.

It seems that IE doesn't properly redraw an item when it's moved across the DOM, and it also fails to reset the hover state unless the mouse re-enters the area. One workaround for this issue is to clone the dragged item instead of using it directly.

To address this problem, you can make use of the sortable() method and specify the following option:

$( ".row" ).sortable({
    connectWith: ".row",
    tolerance: 'pointer',
    helper: 'clone' // added
});

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

To use Jquery draggable, make sure you are running either Jquery minimum version 1.5.0 or version 1.7

I have implemented the following code to enable draggable elements using jQuery: $('.drags').draggable( { cursor: 'move', containment: 'document', helper: function() { var isto = $(this).attr('id'); ...

Ways to adjust the dimensions of an SVG icon in a React application

Trying to figure out how to display an SVG icon and text on the same line in React and Next.js. After some research, I've managed to achieve it. However, I'm struggling to control the size of the SVG icon in relation to the text. Ideally, I want ...

Conceal anchor tag depending on the destination URL

Is there a way to hide anchor tags that point to a specific URL? I am aware of how to do so based on the id using JavaScript: document.getElementById('someID').style.display = 'none'; <a href="#" id="someID" style="display: none"& ...

What steps can be taken to confirm that a comment posted on a specific post is genuine and related to that post?

Currently, I am immersed in the world of AJAX, PHP, and MySQL. Below is a snippet of my PHP code: if(isset($_GET['postTextComment'])){ // The text of the comment $htpc = htmlspecialchars($_GET['postTextComment']); // ID of ...

Issue with tab focus causing dropdown menu to be unresponsive

I'm currently experimenting with a bootstrap example featuring a dropdown menu. Here is the live example: http://jsfiddle.net/p73vc8Lv/ My goal is to have the dropdown menu display when the user clicks on the link. I've attempted to achieve thi ...

JavaScript is reliant on the presence of the alert() function to properly function

I have a JavaScript function that performs well, except for when I remove or comment out the alert() line. This function is designed to calculate the sum of values in up to 30 fields if they are present and contain a value. Here is an example of the HTML ...

Incorporating fancybox on a dynamically loaded AJAX page

After searching extensively within this group and on Google, I have yet to find any answers to my problem. It seems that others have encountered the same issue, but existing threads did not provide a solution. So here I am seeking assistance. The question ...

Chrome's CSS columns cannot contain iframes without causing them to escape their

I'm currently attempting to incorporate Iframes within a 3-column grid. HTML <div id="blogPosts"> <div class="blogPost"> <iframe width="100%" src="https://www.youtube.com/embed/YqeW9_5kURI" frameborder="0" allowfullscre ...

Tips for creating a flexible video layout using HTML

I've been trying to figure out how to make a video responsive in HTML with CSS, but no matter what I do, it just doesn't seem to work. Can someone please provide some guidance? Here is the HTML code that I am using: <div class="container ...

Utilizing Bootstrap and flexbox to create a card: repositioning the image to the left or right

Currently, I am attempting to construct a card layout using Bootstrap 4 with flexbox enabled. The image below depicts my current implementation, which is functioning as expected. https://i.sstatic.net/huXvo.jpg Here is the HTML structure: <section> ...

Issues with border removal due to overflow content in CSS and AngularJS

There seems to be a peculiar issue with overflow content in my application. When you scroll horizontally on the codepen, you'll notice that the border on the .track or perhaps the .cell divs disappears. Any assistance would be greatly appreciated. HT ...

Is it possible to trigger an AJAX call once the AJAX file uploader has finished uploading?

Currently, I am on the lookout for an AJAX File uploader and considering using the one linked below: My dilemma lies in figuring out how to execute a jQuery AJAX call once the file has been successfully uploaded using this uploader. Is there a way to achi ...

develop a dynamic visualization tool using javascript to track steps during page transitions

I have successfully created a unique step progress bar using CSS, and my next objective is to implement page transitions using Javascript. My plan involves utilizing iframes to contain the pages, but I am currently stuck on how to control the transition us ...

Unique title: "Curved Blocks with Unusual Shapes in SVG Path

Hey there, I'm new to working with SVG and Highcharts. I found a jsfiddle online that I would like to customize for my project, but I've encountered an issue with the rounded corner blocks of lines in the Result panel. Here is the link to the js ...

html/css: Collapse container in a horizontal list due to white spaces

I am currently working on creating a horizontal menu for my website. While I have made progress, I am encountering two issues that are interfering with my design. I am exploring two potential solutions: 1). By using the following CSS: #menu li { displa ...

What is the best way to paste plain text into a Textarea without any formatting?

A challenge I am facing in my project is related to copying and pasting text into a Textarea. When a user copies text, the style of the text is also inserted along with it. However, when the user manually types the text, it gets inserted correctly without ...

What is the best way to update the color of an fa icon when an error message is displayed using PHP

I am facing an issue with my form where error messages are displayed on certain input fields. The error messages show up correctly, but I want to change the color of the "fa" icon in the field when its corresponding error message appears. My goal is to ma ...

The custom styles in Material-Table are taking precedence over all other styling, including Material UI styles, and causing icons to not

I recently started using the Material-Table component for a project I'm working on, and it's been great for managing tables with features like adding, editing, deleting, and searching rows. However, I've run into a few issues that I need hel ...

Adjust the height of an iframe dynamically according to the content within using JQUERY/Javascript

My current project involves loading an aspx web page within an iframe. The issue I am facing is that the content inside the iframe can sometimes exceed the height of the iframe itself, resulting in undesired scroll bars. To tackle this problem, I've ...

Number input field failing to update value upon pressing 'enter'

App features an input element that updates when the user presses enter, clicks away, or clicks the next button. Upon inspecting the element in the developer tools, it was observed that the value attribute updates when the user clicks away or clicks the nex ...