我是 Javascript 新手,我一直在尝试在此处找到滑块之前/之后创建此滑块 - https://codepen.io/HarryWilson/pen/jOPzbGz。
document.body.addEventListener('mouseup',function(){
active = false;
overlay = false;
document.querySelector('.scroller').classList.remove('scrolling');
overlayOffDuringSlide();
// this is the area of code which is causing the final problem
});
以上是我确定为问题区域的 JS 代码区域。滑块中的所有内容都在正常工作,除了当您单击任一图像时,叠加层就会消失。我已经确定问题是由 Javascript 的“mouseup”部分引起的,并尝试添加额外的变量或更改我的 if 语句,以便在任何人结束或单击图像时它保持打开状态。
另请参阅此代码笔 - https://codepen.io/HarryWilson/pen/LYVmeZp
document.body.addEventListener('mouseup',function(){
active = false;
overlay = false;
// THis is the problem area
// Maybe check some kinda condition for the overlay being on and if it is, keep it on ...
document.querySelector('.scroller').classList.remove('scrolling');
if (document.querySelector(".overlay").style.display = "block"){
overlayOn();
}
else {
overlayOffDuringSlide();
}
});
在这里,我并排创建了其中两个。上面的代码是我尝试解决方法的方法(它适用于图像单击问题,但是当您在滚动条上鼠标向上时会产生一个新问题。第一个滑块(左侧)显示了单击图像时所需的效果,但是滚动条有一个点击问题。我想出的每一个修复都会给滑块留下一个问题 - 滚动条带回覆盖 onmouseup 或图像将其删除 onmouseup。我希望滑块在您打开时始终显示覆盖图像(即使单击时),然后当您在滚动条上时(即使单击时)覆盖消失。有人可以为此提供建议,因为我似乎只能修复一个并破坏其他?