【发布时间】:2020-06-30 05:37:26
【问题描述】:
更新:这可以在 Chrome 上运行,我如何才能让它在 Firefox 上运行
当我将鼠标悬停在特定元素上时,我试图淡化连续的背景图像。例如,如果我有三个文本元素,并且如果我将鼠标悬停在一个上,我希望背景图像以过渡效果进行更改。
这是我的代码笔:https://codepen.io/tmocodes/pen/MWwXxZO?editors=0110
这是我的灵感来源:https://www.awwwards.com/inspiration/fullscreen-menu-66nord
let seattleEl = document.querySelector("#Seattle");
let ecuadorEl = document.querySelector("#Ecuador");
let arizonaEl = document.querySelector("#Arizona");
let imgArea = document.querySelector(".container");
ecuadorEl.addEventListener("mouseover", e => {
imgArea.style.background = "url('https://www.telegraph.co.uk/content/dam/Travel/2019/November/ecuador.jpg')";
imgArea.classList.add = 'bg'
});
seattleEl.addEventListener("mouseover", e => {
imgArea.style.background =
"url('https://cdn.vox-cdn.com/thumbor/avHeJenMsyJoJ3WBGHl24QWnybk=/0x0:7360x4912/1200x675/filters:focal(3092x1868:4268x3044)/cdn.vox-cdn.com/uploads/chorus_image/image/66498601/shutterstock_482690140.0.jpg')";
imgArea.classList.add = 'bg'
});
*{
padding:0;
margin:0;
box-sizing:border-box
}
.container{
background: url("https://www.telegraph.co.uk/content/dam/Travel/2019/November/ecuador.jpg");
background-size: cover !important;
background-repeat: no-repeat !important;
background-position: center !important;
height:100vh;
transition: all .3s;
h1{
color:white;
opacity: .6;
font-family: Helvetica;
font-size: 48px;
padding: 10px;
cursor:pointer;
display:block;
width:min-content;
height:min-content;
margin-bottom:10px;
&:hover{
opacity:1;
}
}
}
@keyframes transition {
from {
opacity:0
}
to {
opacity:1
}
}
.bg{
background-color: black;
z-index:10;
animation: transition .3s !important;
transition: all .2s;
}
<div class="container">
<h1 id="Ecuador">Ecuador</h1>
<h1 id="Seattle">Seattle</h1>
<h1 id="Arizona">Arizona</h1>
</div>
【问题讨论】:
-
它似乎正在工作,您只需要为最后一个选项添加一个额外的事件处理程序。您能否提供更多信息,说明哪些功能没有按您的预期工作?
-
我刚刚发现了问题!这似乎适用于 chrome 而不是 Firefox。过渡属性似乎正在为背景属性使用 chrome。有没有办法在 Firefox 上解决这个问题?
标签: javascript css animation css-transitions transition