摘要
down
:hover
works on :hover
workson it fade-out after :hover
state is terminated我试着反向使用单独的动画/相同的动画,但没有成功
期望效果
带有标记为.outercontainer
.outercontainer
的屏幕
- Images Fade in on `:hover`
- Images remain visiable so long as the elemet is still in `:hover`
- Images fade-out after the element is "un-hovered"
类似的帖子/问题
之后的背景的图像
在上还有更多类似的问题。我还没有找到一个伪元素后的背景图像的地址
My Questions
取消放置后,是否可以使元素淡出?
My CSS
__and HTML
__are in the snippet (不是完全回复-请全屏打开)
/* Start Miscellaneous stuff */
body {
background: #131418;
color: #999;
text-align: center;
}
.optionlist a {
color: #999;
text-decoration: none;
}
@keyframes mycoolfade {
from {
opacity: 0;
}
to {
opacity: 1;
}
}
/* End Miscellaneous stuff */
.outercontainer {
border: 1px solid blue; /*This needs to be in the middle of the screen and everthing should fit inside it*/
position: fixed; /*border to highlight only - not part of final product*/
top: 50%;
left: 50%;
transform: translate(-50%, -50%);
width: 1200px;
max-width: 80%
}
.optioncontainer {
width: 250px;
max-width: 20vw;
}
.optionlist li {
background: #fff;
padding: .5em;
box-shadow: inset 10px 10px 100px 25px rgba(0, 0, 0, .8);
list-style-type: none;
}
.optionlist li:nth-child(odd) {
background: #000;
}
.optionlist li:hover {
background: red;
}
.optionlist li:hover:after { /* The part the needs to be fixed */
content: '';
width: 800px;
height: 600px;
position: fixed;
top: 50%;
left: 50%;
transform: translate(-50%, -50%);
animation: mycoolfade 1s;
}
/* Start Background Control */
#red:after {background: url(http://lorempixel.com/800/600/)}
#blue:after {background: url(http://lorempixel.com/800/601/)}
#green:after {background: url(http://lorempixel.com/801/600/)}
#yellow:after {background: url(http://lorempixel.com/801/601/)}
#orange:after {background: url(http://lorempixel.com/799/600/)}
#white:after {background: url(http://lorempixel.com/800/599/)}
#black:after {background: url(http://lorempixel.com/801/599/)}
/* End Background Control */
<body>
The initial hiccup when the images load is not an issue
<div class="outercontainer">
<div class="optioncontainer">
<div class="optionlist">
<li id="red">Red</li>
<li id="blue">Blue</li>
<li id="green">Green</li>
<li id="yellow">Yellow</li>
<li id="orange">Orange</li>
<li id="white">White</li>
<li id="black">Black</li>
</div>
</div>
</div>
</body>
编辑:这是理想情况下整个设置的图像。
谢谢。
发布于 2016-12-24 03:16:37
这是我的尝试
也许我漏掉了什么,如果是这样,请告诉我。
诀窍是使optionlist元素的宽度始终为容器宽度的20%。
这样,我们可以使伪元素的父元素占400%,这相当于容器减去optionlist后剩余的80%。
为了处理淡出,我们需要让伪对象始终存在(而不仅仅是在悬停时)。因此,我们将它们声明为不透明度为0的基本状态,并在悬停时将其更改为不透明度1。
这会导致您检测到的bug,因为即使不透明度为0,伪图上的悬停也会触发,然后会冒泡到元素。这可以通过指针-events: none on the伪来解决。
body, html {
height: 100%;
}
body {
background: #131418;
color: #999;
text-align: center;
}
.optionlist a {
color: #999;
text-decoration: none;
}
/* End Miscellaneous stuff */
.outercontainer {
border: 1px solid blue;
/*This needs to be in the middle of the screen t*/
position: relative;
/*border to highlight only - not part of final product*/
top: 50%;
left: 50%;
transform: translate(-50%, -50%);
width: 1200px;
max-width: 80%;
}
.optioncontainer {
width: 20%;
}
.optionlist {
position: relative;
width: 100%;
}
.optionlist li {
background: #fff;
padding: .5em;
box-shadow: inset 10px 10px 100px 25px rgba(0, 0, 0, .8);
list-style-type: none;
}
.optionlist li:nth-child(odd) {
background: #000;
}
.optionlist li:hover {
background: red;
}
.optionlist li:after {
content: '';
width: 400%;
height: 100%;
position: absolute;
top: 0px;
left: 100%;
/*background-size: cover; */
background-position: center;
background-repeat: no-repeat;
opacity: 0;
transition: opacity 1s;
pointer-events: none; /* do not trigger a hover */
}
.optionlist li:hover:after {
opacity: 1;
}
/* Start Background Control */
#red:after {
background-image: url(http://lorempixel.com/800/600/)
}
#blue:after {
background-image: url(http://lorempixel.com/800/601/)
}
#green:after {
background-image: url(http://lorempixel.com/801/600/)
}
#yellow:after {
background-image: url(http://lorempixel.com/801/601/)
}
#orange:after {
background-image: url(http://lorempixel.com/799/600/)
}
#white:after {
background-image: url(http://lorempixel.com/800/599/)
}
#black:after {
background-image: url(http://lorempixel.com/801/599/)
}
<div class="outercontainer">
<div class="optioncontainer">
<div class="optionlist">
<li id="red">Red</li>
<li id="blue">Blue</li>
<li id="green">Green</li>
<li id="yellow">Yellow</li>
<li id="orange">Orange</li>
<li id="white">White</li>
<li id="black">Black</li>
</div>
</div>
</div>
发布于 2016-12-20 14:53:11
只要在你想要的任何地方设置你的outercontainer
即可。在将outercontainer
position
样式更改为relative
和after
之后,将伪元素样式更改为position: absolute; left: 0; top: 0; width: 100%; height: 100%;
似乎可以很好地满足您的需要。使用CSS动画,您可以应用淡入淡出效果。
============最新更改==============
添加了与位置和页边距相关的outercontainer
样式以将其显示在中心,添加了伪元素background
样式,如no-repeat
和background-size: cover
。已将div
标记更改为ul
和ul
的flex
样式。
/* Start Miscellaneous stuff */
body {
background: #131418;
color: #999;
text-align: center;
}
.optionlist a {
color: #999;
text-decoration: none;
}
@keyframes mycoolfade {
from {
opacity: 0;
}
to {
opacity: 1;
}
}
/* End Miscellaneous stuff */
.outercontainer {
border: 1px solid blue; /*This needs to be in the middle of the screen and everthing should fit inside it*/
position: absolute; /*border to highlight only - not part of final product*/
top: 0;
left: 0;
right: 0;
bottom: 0;
margin: auto;
min-width: 50%;
min-height: 50%;
width: 80%;
height: 80%;
transform: translate(-50%, -50%);
}
.optioncontainer {
width: 250px;
max-width: 20vw;
height: 100%;
}
.optionlist {
padding: 0;
margin: 0;
display: flex;
flex-direction: column;
height: 100%;
}
.optionlist li {
background: #fff;
padding: .5em;
box-shadow: inset 10px 10px 100px 25px rgba(0, 0, 0, .8);
list-style-type: none;
}
.optionlist li:nth-child(odd) {
background: #000;
}
.optionlist li:hover {
background: red;
}
.optionlist li:hover:after { /* The part the needs to be fixed */
content: '';
width: 100%;
height: 100%;
position: absolute;
top: 0;
left: 0;
transform: translate(-50%, -50%);
animation: mycoolfade 1s;
z-index:-1;
}
/* Start Background Control */
#red:after {
background: url(http://lorempixel.com/800/600/) no-repeat center center fixed;
-webkit-background-size: cover;
-moz-background-size: cover;
-o-background-size: cover;
background-size: cover;
}
#blue:after {
background: url(http://lorempixel.com/800/601/) no-repeat center center fixed;
-webkit-background-size: cover;
-moz-background-size: cover;
-o-background-size: cover;
background-size: cover;
}
#green:after {
background: url(http://lorempixel.com/801/600/) no-repeat center center fixed;
-webkit-background-size: cover;
-moz-background-size: cover;
-o-background-size: cover;
background-size: cover;
}
#yellow:after {
background: url(http://lorempixel.com/801/601/) no-repeat center center fixed;
-webkit-background-size: cover;
-moz-background-size: cover;
-o-background-size: cover;
background-size: cover;
}
#orange:after {
background: url(http://lorempixel.com/799/600/) no-repeat center center fixed;
-webkit-background-size: cover;
-moz-background-size: cover;
-o-background-size: cover;
background-size: cover;
}
#white:after {
background: url(http://lorempixel.com/800/599/) no-repeat center center fixed;
-webkit-background-size: cover;
-moz-background-size: cover;
-o-background-size: cover;
background-size: cover;
}
#black:after {
background: url(http://lorempixel.com/801/599/) no-repeat center center fixed;
-webkit-background-size: cover;
-moz-background-size: cover;
-o-background-size: cover;
background-size: cover;
}
/* End Background Control */
<body>
The initial hiccup when the images load is not an issue
<div class="outercontainer">
<div class="optioncontainer">
<ul class="optionlist">
<li id="red">Red</li>
<li id="blue">Blue</li>
<li id="green">Green</li>
<li id="yellow">Yellow</li>
<li id="orange">Orange</li>
<li id="white">White</li>
<li id="black">Black</li>
</ul>
</div>
</div>
</body>
发布于 2016-12-23 19:53:35
你问题的fadein/fadeout部分:
/* Start Miscellaneous stuff */
body {
background: #131418;
color: #999;
text-align: center;
}
.optionlist a {
color: #999;
text-decoration: none;
}
/* End Miscellaneous stuff */
.outercontainer {
border: 1px solid blue; /*This needs to be in the middle of the screen and everthing should fit inside it*/
position: fixed; /*border to highlight only - not part of final product*/
top: 50%;
left: 50%;
transform: translate(-50%, -50%);
width: 1200px;
max-width: 80%
}
.optioncontainer {
width: 250px;
max-width: 20vw;
}
.optionlist li {
background: #fff;
padding: .5em;
box-shadow: inset 10px 10px 100px 25px rgba(0, 0, 0, .8);
list-style-type: none;
}
.optionlist li:nth-child(odd) {
background: #000;
}
.optionlist li:hover {
background: red;
}
.optionlist li:after {
content: '';
width: 800px;
height: 600px;
position: fixed;
top: 50%;
left: 50%;
transform: translate(-50%, -50%);
transition: opacity 1s;
opacity: 0;
pointer-events: none;
}
.optionlist li:hover:after {
opacity: 1;
pointer-events: auto;
}
/* Start Background Control */
#red:after {background: url(http://lorempixel.com/800/600/)}
#blue:after {background: url(http://lorempixel.com/800/601/)}
#green:after {background: url(http://lorempixel.com/801/600/)}
#yellow:after {background: url(http://lorempixel.com/801/601/)}
#orange:after {background: url(http://lorempixel.com/799/600/)}
#white:after {background: url(http://lorempixel.com/800/599/)}
#black:after {background: url(http://lorempixel.com/801/599/)}
/* End Background Control */
<body>
The initial hiccup when the images load is not an issue
<div class="outercontainer">
<div class="optioncontainer">
<div class="optionlist">
<li id="red">Red</li>
<li id="blue">Blue</li>
<li id="green">Green</li>
<li id="yellow">Yellow</li>
<li id="orange">Orange</li>
<li id="white">White</li>
<li id="black">Black</li>
</div>
</div>
</div>
</body>
https://stackoverflow.com/questions/41236294
复制相似问题