我有一个div,通过CSS悬停展开。当用户点击div时,我希望它保持在这个宽度。到目前为止,我有这个工作。悬停时切换宽度,保持点击,释放点击并点击关
但是,当用户再次单击div(切换)并且用户单击文档其余部分的div时,我需要将div折叠回原始大小。
jQuery的位置:
$(".rail").click(function() {
$(".rail").width(180);
});
此处的CSS:
.rail{
width: 30px;
border-left: 10px solid #ff5400;
position: absolute;
top: 0px;
bottom: 0px;
right: 0px;
background-color: rgba(0,0,0,0.15);
cursor: pointer;
-webkit-transition: all .3s ease-in-out;
-moz-transition: all .3s ease-in-out;
-o-transition: all .3s ease-in-out;
transition: all .3s ease-in-out;
}
.rail:hover{
width: 180px;
background-color: #ddd;
-webkit-transition: all .3s ease-in-out;
-moz-transition: all .3s ease-in-out;
-o-transition: all .3s ease-in-out;
transition: all .3s ease-in-out;
}
不知道为什么这是公认的答案。这是复杂的两倍。 :\ – teh1
@ teh1 - 并非如此,我只是在jQuery中做了悬停的东西,因为我喜欢将它全部放在一个地方,如果删除了悬停功能,它几乎和你的答案一样。 – adeneo
虽然这是非常侵扰性的。拿出jQuery将彻底打破它。使用我的方法,它将完全起作用,除非在没有jQuery的情况下单击时展开。别担心。 – teh1