【发布时间】:2018-04-15 07:11:02
【问题描述】:
我正在为网站主页制作幻灯片。我使用 CSS 构建了当幻灯片悬停时出现的箭头按钮。但我认为很酷的一个功能是能够在一段时间后鼠标消失,按钮消失。我对使用 JS 或 CSS 的答案很好。这是我的代码:
.master {
display: none;
width: 100vw;
}
.mcont {
background-image: url("../Pictures/magtrans.jpg");
padding: auto;
text-align: center;
width: 100vw;
height: 100vh;
background-repeat: no-repeat;
background-size: 100% 100%;
background-position: center;
}
.hover {
height: 100vh;
}
.mtext {
color: #ffffff;
display: table;
background-color: rgba(0, 0, 0, 0.5);
margin: auto;
padding: 3vw;
position: relative;
top: 50%;
-webkit-transform: translateY(-50%);
-ms-transform: translateY(-50%);
transform: translateY(-50%);
font-family: helvetica, arial, sans-serif;
}
.mtext h1 {
padding: 0;
margin: 0;
padding-bottom: 1vh;
font-size: 5vh;
}
.mtext p {
padding: 0;
margin: 0;
padding-bottom: 2.5vh;
font-weight: bold;
font-size: 2vh;
}
.mtext button {
background-color: #5555ff;
border: none;
color: #ffffff;
padding: 15px 32px;
text-align: center;
text-decoration: none;
display: inline-block;
font-size: 16px;
outline: none;
font-weight: bold;
cursor: pointer;
-webkit-transition: background-color 2s;
transition: background-color 2s;
}
.mtext button:hover {
background-color: #55aaff;
}
.leftc, .rightc {
border-radius: 50%;
width: 5vw;
height: 5vw;
background-color: rgba(0, 0, 0, 0.5);
vertical-align: middle;
border: none;
cursor: pointer;
outline: none;
color: #ffffff;
font-size: 3vw;
position: absolute;
top: 50%;
-webkit-transform: translateY(-50%);
-ms-transform: translateY(-50%);
transform: translateY(-50%);
font-family: helvetica, arial, sans-serif;
opacity: 0;
-webkit-transition: opacity 1s;
transition: opacity 1s;
}
.hover:hover > .leftc {
opacity: 1.0;
}
.hover:hover > .rightc {
opacity: 1.0;
}
.leftc {
left: 1vw;
}
.rightc {
right: 1vw;
}
<div class='mcont'>
<img class='master' src='Media/Pictures/magtrans.jpg'/>
<div class='hover'>
<button class='leftc'><</button>
<button class='rightc'>></button>
<div class='mtext'>
<h1>Slideshow</h1>
<p>Buttons to left and right!</p>
<button>Learn More</button>
</div>
</div>
</div>
我需要的是类似于 Google 幻灯片中的内容,其中光标和工具栏会在几秒钟后消失,并在鼠标移动时返回。我对 CSS 过渡和动画进行了广泛的研究。动画 cursor 可以,但 cursor 不可动画。
【问题讨论】:
-
即使您正在共享一些代码,它与要求无关,并且您在实现目标方面取得了 0 个进展(并且没有编码尝试)。这使您成为要求免费工作的客户。如果您不想要这种状态,请更改它:(重新)搜索,尝试对其进行编码,询问我们为什么某些 CSS 或 JS 没有按照您的想法执行,即使文档让您相信它应该执行,等等......所以不是免费的编码服务。简而言之,我们只是一群程序员互相传授技巧和编码最佳实践。我们不是来工作的。
-
@AndreiGheorghiu 我彻底研究了 CSS 过渡和动画,但一无所获。但我当然同意,SO 不是免费的编码服务。
-
那是因为您不能使用 CSS 在鼠标移动时运行代码。您必须为此使用 Javascript。最简单的解决方案是在鼠标移动时添加/删除一个类。
-
你说得对,在我问 SO 之前,我可能应该研究/尝试过一些 JS。我只是希望我在某个地方错过了一些明显的答案,而且我不会花半个小时来编写 JS 来做一些你可以用三行 CSS 做的事情。
标签: css css-transitions