我有一个通过 CSS 在悬停时展开的 div。当用户单击 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;
}