Troubleshooting: Javascript Opacity Slider Malfunctioning on Internet Explorer

I was looking for a way to change the color of an image using a slider. I decided to tweak some Javascript code so that it alters the opacity of a different colored image layered on top of the original one as the slider is adjusted. Additionally, I incorporated a dimming feature that utilizes opacity and a black overlay to dim the image.

Everything runs smoothly in Chrome and Firefox, but I can't seem to get it working in Internet Explorer. As a newcomer to Javascript, I'm struggling to pinpoint the issue. Any assistance would be greatly appreciated!

HTML

<img src="images/warm-1170.jpg" id="warm">
<img src="images/cool-1170.jpg" id="cool">
<div class="blackBoxDimmer" id="dimmer"></div>
<div id="slidecontainer">
    <input type="range" min="0" max=".99" step=".01" value=".5" class="slider" id="myRange">
</div>
<p id="x1">2700K</p>
<p id="x2">5000K</p>
<h4 id="sliderTitleColor">Color Adjustment</h4>
<div id="dimAdjustSlider">
<div id="slidecontainer">
    <input type="range" min="0" max=".5" step=".01" value="0" class="slider" id="myRangeDim">
</div>
</div>
<p id="y1">5%</p>
<p id="y2">100%</p>
<h4 id="sliderTitleDim">Dimming Function</h4>

CSS

body {
    font-family: "arial", serif;
}
.container {
    width: 1170px;
    margin: 0 auto;
    padding: 0;
}
.blackBoxDimmer {
    display: block;
    width: 1170px; /* !!!Adjust this to match image width */
    height: 671px; /* !!!Adjust this to match image height */
    margin-top: -675px;
    opacity: 0;
    background-color: black;
}
#warm {
    position: absolute;
}
#cool {
    opacity: .5;
}
input[type=range] {
  /*removes default webkit styles*/
  -webkit-appearance: none;
  /*fix for FF unable to apply focus style bug */
  border: 1px solid white;
  /*required for proper track sizing in FF*/
  width: 800px;
}
input[type=range]::-webkit-slider-runnable-track {
  width: 800px;
  height: 5px;
  background: #ddd;
  border: none;
  border-radius: 3px;
}
input[type=range]::-webkit-slider-thumb {
  -webkit-appearance: none;
  border: none;
  height: 16px;
  width: 16px;
  border-radius: 50%;
  background: #82c341;
  margin-top: -4px;
}
input[type=range]:focus {
  outline: none;
}
input[type=range]:focus::-webkit-slider-runnable-track {
  background: #ccc;
}
input[type=range]::-moz-range-track {
  width: 800px;
  height: 5px;
  background: #ddd;
  border: none;
  border-radius: 3px;
}
input[type=range]::-moz-range-thumb {
  border: none;
  height: 16px;
  width: 16px;
  border-radius: 50%;
  background: #82c341;
}
/*hide the outline behind the border*/

input[type=range]:-moz-focusring {
  outline: 1px solid white;
  outline-offset: -1px;
}

input[type=range]::-ms-track {
  width: 800px;
  height: 5px;
  /*remove bg colour from the track, we'll use ms-fill-lower and ms-fill-upper instead */
  background: transparent;
  /*leave room for the larger thumb to overflow with a transparent border */
  border-color: transparent;
  border-width: 6px 0;
  /*remove default tick marks*/
  color: transparent;
}

input[type=range]::-ms-fill-lower {
  background: #777;
  border-radius: 10px;
}

input[type=range]::-ms-fill-upper {
  background: #ddd;
  border-radius: 10px;
}

input[type=range]::-ms-thumb {
  border: none;
  height: 16px;
  width: 16px;
  border-radius: 50%;
  background: #82c341;
}
input[type=range]:focus::-ms-fill-lower {
  background: #888;
}
input[type=range]:focus::-ms-fill-upper {
  background: #ccc;
}
#slidecontainer {
    margin-top: 50px;
    margin-left: 180px;
}
#dimAdjustSlider {
    display: inline-block;
    transform: rotate(180deg);
    margin-left: 180px;
    margin-bottom: 50px;
}
#y1 {
    display: inline-block;
    position: absolute;
    font-size: 12px !important;
    margin: 25px 0 0 -972px;
}
#y2 {
    display: inline-block;
    position: absolute;
    font-size: 12px !important;
    margin: 25px 0 0 -233px;
}
#sliderTitleDim {
    margin-top: -70px;
    margin-left: 513px;
    margin-bottom: 75px;
}
.dimmingBox {
    display: block;
}
#x1 {
    display: inline-block;
    font-size: 12px !important;
    margin-left: 190px;
    margin-right: 705px;
    margin-bottom: 30px;
}

#x2 {
    display: inline-block;
    font-size: 12px !important;
}

#sliderTitleColor {
    margin-top: -30px;
    margin-bottom: 45px;
    margin-left: 513px;
}
.textAlignLeft {
    text-align: left !important;
}

Javascript

var slider = document.getElementById("myRange");
        var output = .5;
        var imageTrans = document.getElementById("cool");
        output.innerHTML = slider.value; // Display the default slider value

        // Update the current slider value (each time you drag the slider handle)
        slider.oninput = function() {
            output.innerHTML = this.value;
            imageTrans.style.opacity = slider.value;
        }

        var sliderDim = document.getElementById("myRangeDim");
        var outputDim = 0;
        var imageTransDim = document.getElementById("dimmer");
        outputDim.innerHTML = sliderDim.value; // Display the default slider value

        // Update the current slider value (each time you drag the slider handle)
        sliderDim.oninput = function() {
            outputDim.innerHTML = this.value;
            imageTransDim.style.opacity = sliderDim.value;
        }

Any help is welcomed! Thank you!

Answer №1

To ensure compatibility with older versions of Internet Explorer, consider switching the event that triggers your JavaScript function from oninput to either onchange or onmousemove.

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

Issue with implementing setTimeout on await fetch() result

I'm trying to figure out how to add a setTimeout to my request response when using await fetch. Currently, each response is being sent to a DIV in the HTML, but I want to introduce a delay of 5 seconds before each response appears. I attempted this s ...

How can I customize the offset and achieve a smooth transition to each section using Jquery or JavaScript in Bootstrap scrollspy?

My goal is to customize the scrollspy offset and create a smooth transition between sections without relying on plugins or data attributes. I have a JavaScript function that sets the offset for scrollspy, but I need help adding a smooth animated scroll eff ...

Implementing JSON methods in C# WebService to enable communication with external servers

Is it possible to integrate an asp.net web service written in C# into an HTML5/JavaScript website? The challenge is that the web service and client are located on different domains, requiring a cross-domain request. ...

What could be causing the count button to malfunction on my Oracle APEX form?

I am working on creating 2 buttons that can adjust the quantity of products on an orderline, either increasing or decreasing it. https://i.sstatic.net/kFOkP.png My goal is to have the plus and minus buttons modify the quantity value when clicked. I att ...

Arrange arrays with multiple dimensions in JavaScript based on their ranges

Seeking assistance on sorting a multi-dimensional array returned from an API to enable users to choose a range based on beats. I'm currently facing challenges with the data my API is returning. var myObj = [{ title: 'title one', be ...

Using a combination of CSS selector, several attributes, and the OR operator

Can you assist me with CSS selectors? Let's say we have a style HTML tag: <style type="text/css"> [...selector...] {color:red;} </style> I want to create a selector with multiple attributes and logical operators, but I am uncertain about ...

PhoneGap switches up the error type with each consecutive run

Why does PhoneGap change errors after every time it is compiled? Sometimes it runs without any issues, but then the same code throws strange errors like parse error or function not found, even though no changes were made to the code. Here is the code that ...

Hide the button with jQuery if the variable is empty

As I delve into the world of learning javascript/jQuery on my own, I encountered a bit of difficulty. To tackle this challenge, I created an internal logo repository for easy access to all the logos required by the company. The issue arises from having a ...

Sending a text parameter to the JavaScript Executor within a Selenium framework

Although this question has been asked before, I have searched for multiple answers and have not found a solution to my specific problem. if (driver instanceof JavascriptExecutor) { System.out.println("In try"); ((JavascriptExecutor)driver) ...

Video demo: Issue with Bootstrap navigation bar expansion being truncated

When developing my React app, I installed the latest Bootstrap using npm by running: npm install bootstrap followed by: npm install bootstrap jquery and then: npm install jquery popper.js Initially, my Navbar functioned perfectly when the window was wid ...

Refresh gif without having to reload it in Internet Explorer 11

I'm attempting to create a feature where a gif restarts when clicked by the user, without needing to reload it (due to the heavy size of the gif which is preloaded for my application). The current code functions flawlessly on Chrome and other "modern ...

What could be the reason for my clickable div not functioning as a link in this particular code?

Here is my jQuery script: $('.projektet').click(function(){ var url = $(this).find("a").attr("href"); window.location = url; }); <div class='projektet'> <h3>".$alias." ".$expertis." ".$other."</h3> & ...

I desire for an element to reduce in size relative to the amount of space occupied by the adjacent element on the screen

Is there a better solution to adjust the size of the divider line on the picture based on the All publications link? I have implemented it this way so far, but I'm open to other suggestions. https://i.sstatic.net/UBl1n.png @media (max-width: 767px) ...

The echo function is repeating something that is not text

I have set up a basic bottle server using Python: from bottle import route, run, static_file @route('/') def home(): return static_file("home.html", root='.') @route("/<fileName>") def respond(fileName): return static_f ...

Ways to customize the alignment of nav-link items in Bootstrap 4

I am using Bootstrap 4 and have a set of three nav-link elements: <ul class="nav nav-pills"> <li class="nav-item"> <a class="nav-link active" href="#">Item1</a> </li> <li class="nav-item"> <a class="nav ...

Ways to validate code that relies on browser APIs

I am currently utilizing Node to run my unit-tests. There is a JavaScript module that I need to test in the browser. My code is considered "isomorphic", meaning it does not use language features that are unavailable in Node, such as exports. However, it ...

Troubleshooting problem with presenting real-time data in a Bootstrap Carousel using PHP

Currently, I am in the process of developing a dynamic events calendar to showcase on a website homepage. The information displayed on this calendar is retrieved from a database using PHP. Additionally, I have implemented the Bootstrap framework (version 4 ...

Is there an issue with using $_POST in an ajax form submission?

Whenever I attempt to verify if a user-inputted name already exists through an ajax form submission, all I receive is an error stating "Undefined index: username" in the sessions.php file. What could be causing this issue? <form action="" method="POST" ...

Marquee is experiencing issues with incomplete scrolling

Hello everyone, I have been trying to implement a stock market ticker on my website. Initially, I used the marquee tag and it worked fine. Then I tried using simple scroll within the PHP UserCake user management system, but unfortunately, it is not working ...

When retrieving values from an array using an index, it may result in

I am attempting to access a specific index of an array within a JSON object. For instance, here is the JSON object retrieved from MongoDB: { _id: 55b65199c92d15d80fd94803, site: 'test.com', company: 'test', __v: 0, votes: [ ...