【发布时间】:2019-06-15 02:49:29
【问题描述】:
所以我有一个播放音频的图像,并在单击时更改图像。我在图像下方还有一个音量滑块。我的问题是,当鼠标悬停在图像上时,如何让滑块淡入淡出?
当悬停在滑块本身而不是图像上时,会出现滑块。我尝试将不透明度设置为变量并通过 JavaScript 更改它,但这似乎没有任何作用。
function CoffeeChange() {
if (Coffee.src == "https://static.wixstatic.com/media/38d0c2_f65cba752ac3460da7a56896d1195284~mv2.png") {
Coffee.src = "https://static.wixstatic.com/media/38d0c2_37f01de3219a4804a3cb29f39e57b48c~mv2.png";
} else {
Coffee.src = "https://static.wixstatic.com/media/38d0c2_f65cba752ac3460da7a56896d1195284~mv2.png";
}}
document.getElementById("Coffee").onclick = function() {
CoffeeChange()
var audio = document.getElementById("CoffeeAudio");
if (audio.paused) audio.play();
else audio.pause();
};
volume.addEventListener("mousemove", coffeeVolume);
function coffeeVolume(){
document.getElementById("CoffeeAudio").volume = document.getElementById("volume").value / 100;
}
.slidecontainer {
width: 100%;
}
.slider {
-webkit-appearance: none;
width: 100px;
height: 15px;
border-radius: 5px;
background: #d3d3d3;
outline: none;
-webkit-transition: .2s;
transition: opacity .2s;
position: relative;
top: 130px;
opacity:0;
}
.slider:hover {
opacity: 1;
}
.slider::-webkit-slider-thumb {
-webkit-appearance: none;
appearance: none;
width: 25px;
height: 25px;
border-radius: 50%;
background: #4CAF50;
cursor: pointer;
}
.slider::-moz-range-thumb {
width: 25px;
height: 25px;
border-radius: 50%;
background: #4CAF50;
cursor: pointer;
}
<meta name="viewport" content="width=device-width, initial-scale=1">
<div class="slidecontainer">
<input type="range" min="0" max="100" value="100" class="slider" id="volume">
</div>
<img id="Coffee" src="https://static.wixstatic.com/media/38d0c2_f65cba752ac3460da7a56896d1195284~mv2.png"
height="100" width="100">
<audio id="CoffeeAudio" loop>
<source src="//music.wixstatic.com/preview/38d0c2_02a2ea74abbc49a29ae7bdfabd1091d0-128.mp3" type="audio/wav" />
</audio>
我已经添加了整个代码,以明确我是如何做我迄今为止所做的事情的,以防万一有任何事情可能会阻止它工作。
【问题讨论】: