【发布时间】:2019-02-04 05:03:21
【问题描述】:
我正在使用 html/css/javascript 创建幻灯片。它应该看起来像显示新图像的图像轨迹,因为最后显示的图像悬停在上面。但我只能让第一张图片出现。我写的用于继续幻灯片效果的功能无效。函数中缺少什么?
<div class = "line1">
<img class = "crash" src = "../Pics/January_2019/crash2.jpg" alt = "Another picture you can't see" onmouseover = "mover ()" onmouseout = "mout ()">
<img class = "crash" src = "../Pics/January_2019/crash3.jpg" alt = "You must be blind" onmouseover = "mover ()" onmouseout = "mout ()">
<img id = "second" src = "../Pics/January_2019/screen.jpg" alt = "It's a mirror" >
</div>
<br></br>
<div class = "line2">
<img class = "crash" src = "../Pics/January_2019/crash4.jpg" alt = "Or we're not linking up" onmouseover = "mover ()" onmouseout = "mout ()">
<img class = "crash" src = "../Pics/January_2019/crash5.jpg" alt = "Still checkin?" onmouseover = "mover ()" onmouseout = "mout ()">
<img id = "third" src = "../Pics/January_2019/NYbridge.jpg" alt = "A bridge you can't see">
</div>
css
.crash {
display: none;
}
.brash {
display: inline-flex;
width: 21%;
padding: 0.75%;
margin: 0.75%;
}
.line1, .line2 {
display: flex;
}
js
let shine = document.querySelectorAll('.crash');
const glide = document.querySelector('#first');
let count;
如果我指定计数 (=) 而不是比较它 (==),则会弹出第一张图片幻灯片。否则,当我将鼠标悬停在第一张图片上时,什么都不会显示。
mover = function () {
if (count == 4) {
count = 0;
}
shine[count].classList.replace('crash', 'brash');
}
mout = function => {setTimeout (removefunc, 200)}
removefunc = function () {
if (count >= 1) {
shine[count].classList.replace ('brash', 'crash');
}
count+=1;
}
glide.onmouseover = mover;
glide.onmouseout = mout;
shine[0].onmouseover = mover;
shine[0].onmouseout = mout;
【问题讨论】:
标签: javascript html css selectors-api