gpt4 book ai didi

Javascript 不透明度 slider 在 Internet Explorer 中不起作用

转载 作者:行者123 更新时间:2023-11-28 02:37:16 25 4
gpt4 key购买 nike

我需要一个组件来使用 slider 更改图像的颜色。为此,我修改了 Javascript 代码以在 slider 移动时更改原始图像顶部不同颜色图像的不透明度。我还添加了一个调光功能,使用不透明度和黑色 div 使图像变暗。

它在 Chrome 和 Firefox 中完美运行。我一辈子都想不出如何让它在 Internet Explorer 中工作。我是 Javascript 的新手,所以这可能很明显,但有人可以帮忙吗?!?

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;
}

谢谢!

最佳答案

对于老 IE 用户,您可能需要更改附加 javascript 函数的事件 - 从 oninputonchangeonmousemove

关于Javascript 不透明度 slider 在 Internet Explorer 中不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47356291/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com