Creating a dynamic CSS hover animation for an input element with jQuery to ensure compatibility with Microsoft Edge

I am facing an issue where I have a row of six to nine switches with the <input type="checkbox"> element, and each switch animates when hovered over. In this animation, the knob slides down, and both the knob and track fill with colors or gradients. However, the hover animation doesn't work in Edge browser.

Since I lack sufficient knowledge of jQuery, I am unsure how to recreate this animation using jQuery instead of CSS to ensure compatibility with Edge.

I am confused about which part of the CSS code needs to be transferred to jQuery for this animation to function correctly.

It seems that Edge has limitations with handling hover events on elements other than links. This further complicates my attempt to make it work using jQuery.

How can I implement this functionality using jQuery for the switches, rather than relying solely on CSS?

I have reviewed other queries and responses related to similar issues, but they mostly deal with images or links, not input elements like switches. Here is the codepen link with additional comments: https://codepen.io/akajezebel/pen/PrQoJe

The HTML structure:

<!DOCTYPE html>
    <html>
    <head>
    <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.4.1/jquery.min.js"> 
   </script>
    </head>
    <body>
      <div class="switch-row">
       <label class="switch">
         <a href="https://www.linkedin.com/" target="_blank" rel="noopener noreferrer">
           <input class="knob" type="checkbox">
           <span class="slider round"></span>
         </a>
         </label>
      </div>
      <div class="switch-row">
       <label class="switch">
          <a href="https://www.twitter.com/" target="_blank" rel="noopener noreferrer">
            <input class="knob" type="checkbox">
           <span class="slider round"></span>
         </a>
       </label>
      </div>
    </body>
    </html>

The existing CSS styles:

(CSS code provided)

I am referencing the following jQuery example from http://jsfiddle.net/q61n8gxv/2/, hoping to gain insights into making this transition from CSS to jQuery smoother.

(jQuery code provided)

My goal is to replicate the CSS behavior of the switches using jQuery. The desired outcome includes the knob sliding down, filling with gradients upon hover/mouseenter, and reverting back to the initial state upon mouseout.

Answer №1

It is likely that Internet Explorer does not recognize when your input has been resized to 0. Here is an alternative approach you can try:

.switch {
  display: inline-block;
  height: 113px;
  margin: 10px 23px;
  position: relative;
  width: 55px;
  overflow: hidden;
}

.switch input {
  position: absolute;
  top: 0;
  left: 0;
  height: 100%;
  width: 100%;
  opacity: 0.001;
  z-index: 1
}

.slider {
  border: 1px solid #cc80ff;
  bottom: 0;
  cursor: pointer;
  left: 0;
  position: absolute;
  right: 0;
  top: 0;
  -moz-transition: 0.4s;
  -o-transition: 0.4s;
  -webkit-transition: 0.4s;
  transition: 0.4s;
}

.slider::before {
  border: 1px solid #cc80ff;
  bottom: 60px;
  content: "";
  height: 43px;
  left: 5px;
  position: absolute;
  -moz-transition: 0.4s;
  -o-transition: 0.4s;
  -webkit-transition: 0.4s;
  transition: 0.4s;
  width: 43px;
}

input:hover+.slider {
  background-color: #cc80ff;
  background-color: rgba(204, 128, 255, 0.8);
}

input:focus+.slider {
  box-shadow: 0 0 1px #cc80ff;
}
    
/* More CSS styling rules here */

<div class="switch-row">
  <label class="switch">
         <a href="https://www.linkedin.com/" target="_blank" rel="noopener noreferrer">
           <input class="knob" type="checkbox">
           <span class="slider round"></span>
         </a>
         </label>
</div>
<div class="switch-row">
  <label class="switch">
          <a href="https://www.twitter.com/" target="_blank" rel="noopener noreferrer">
            <input class="knob" type="checkbox">
           <span class="slider round"></span>
         </a>
       </label>
</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

I possess a button that decreases the value of a number in the database when pressed. I desire for this action to occur repeatedly without fail

I have a button that, when pressed, decreases a number in my database by one. I want this action to decrement the number each time it is clicked. Code in HTML and PHP <form method="post"> <div><?php $username = "root" ...

What is the method for incorporating a dotted line preceding the menu options?

I am currently working on an asp.net menu that looks like this: <div id="left"> <div id="menus" runat="server"> <div id="left_menu"> <div class="abc"> < ...

Instead of loading the HTML into the div, Ajax is now sending me the link instead

I have just begun working on a new laravel project and am currently working on the user profile page, which will include a sidebar with links like Portfolio, Account Settings, etc. My goal is to dynamically load each page into a div when a link in the side ...

The program waited for 60 seconds for the element to become clickable in the Selenium webdriver, but it timed out

I am currently working on Selenium web driver and trying to locate the element with the ID visualizationId, but I keep encountering an error. Below is the code snippet where the error occurs: Actions actions1 = new Actions(driver); WebElement dBox1= ((new ...

Concerns with combining key value pairs in Typescript Enums

Could you help me figure out how to properly implement an enum in my drop-down so that I can only display one value at a time? Currently, I am seeing both the key and the value in the list. This is my enum: export enum VMRole { "Kubemaster" = 0, "Kub ...

Guide on transferring JSON data to a PHP script by utilizing jQuery's submit function

Hey there, I am just starting to explore JSON in jQuery. I have created an HTML form using JSON data and JavaScript, where the JSON string holds the result. My question is how do I send this string to a PHP file? I am currently using an ajax function to ...

The issue of Firefox background image flickering is persistent when multiple instances are open and the background-size

I am facing an issue with background images on my webpage. I have two elements that share a background image and are contained within 3 column width containers using Bootstrap. In the second element, I have set the background to be 90% in width, making it ...

Having trouble with conditional statements in jQuery when handling ajax responses?

I am currently working with the following code: $.ajax({ url: 'upload.php', //Server script to process data type: 'POST', xhr: function() { // Custom XMLHttpRequest var myXhr = $.ajaxSettings.xhr(); if(myX ...

Issue encountered while presenting canvas on HTML due to Firebase information

Even though I believe I'm following the correct steps, I am facing an issue where the graph displaying real-time database values is not showing up. The first image shows my real-time database and a demostration as shown in images 2 and 3. While the da ...

``There seems to be an issue with the jquery Waterfall plugin where it is not properly waiting for

Utilizing the waterfall plugin with jQuery on my website has been a smooth experience. My current setup involves jQuery 1.9.1 along with Knockout.js for my JavaScript view model. The data is fetched through an ajax call to a web API service, delivering JSO ...

aligning two elements within a container to have equal heights

I need to position 2 divs inside a container div. Their height should always be the same, regardless of content. To achieve this, I am using absolute positioning with top and bottom set to 0. Currently, the container div #three collapses and hides the cont ...

Is it feasible to unload modules in Node.js once they have been loaded?

app.post('/userlogin',function(req,res){ var Module1=require('./lib/module1'); app.use(Module1); var Module2=require('./lib/module2'); app.use(Module2); }); Is it possible to unload or destroy the modules after they ...

Connecting a picture to a web address using the <img class> tag

I'm facing a major issue with the "fade script" I added to my portfolio. It's designed to fade between thumbnails using jQuery and CSS, but it relies on 2 img classes that I can't seem to link properly. Basically, I want to link the image g ...

Issue with jquery selector function when handling ajax response containing HTML data

Within my jquery code, I have implemented an ajax get function to retrieve the html code of a specific page. My objective is to extract a particular element from this html content. However, when attempting to do so, jquery throws the following error: SCRI ...

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 ...

Scrape embedded content within an IFrame on a webpage with Java

Currently, I am interested in crawling the dynamic content within an IFramed webpage; Unfortunately, none of the crawlers I have tested so far (Aperture, Crawl4j) seem to support this feature. The result I typically get is: <iframe id="template_cont ...

Create a path on the Google Map that follows the designated route

I am looking for a solution similar to one found here: Sample However, I have been unable to find a suitable solution anywhere. The main issue is being able to follow the route in order to draw a line between two points. Can anyone provide guidance on ho ...

Guide on displaying four calendars simultaneously on a single page using the fullCalendar plugin

I'm looking to display four unique calendars on a single webpage using the full calendar plugin. While I am new to the jQuery full calendar plugin, I have managed to identify four separate IDs for each calendar. My goal is to write the necessary jQuer ...

Obtain the document from the jQuery AJAX response

I am currently working on generating a word document on the server side in response to an ajax event. If there are no errors, I would like to trigger a download of the file. Is it possible to achieve this with jQuery ajax? My current code snippet looks l ...

Utilizing a Recycled jQuery UI Themeroller Overlay

I'm looking to optimize css-loading bandwidth by reusing the overlay from jQuery UI for a specific section of my page. However, I'm encountering an issue where the overlay only covers a semi-transparent blackout of the entire page instead of just ...