dja*_*ngo 5 html jquery sidebar slidetoggle
我正在尝试创建一个具有类似效果的滑动侧栏
这是我写代码的距离.但这是生涩的.
有任何想法吗 ?
CSS
#slide{
border:1.5px solid black;
position:absolute;
top:0;
left:0;
width:150px;
height:100%;
background-color:#F2F2F2;
layer-background-color:#F2F2F2;
}
Run Code Online (Sandbox Code Playgroud)
HTML
<div id="slide" style="left: -150px; top: 0px; width: 160px;">
<p>Something here</p>
</div>
Run Code Online (Sandbox Code Playgroud)
jQuery的
<script>
jQuery(document).ready(function() {
$('#slide').mouseover(function() {
$("#slide").css("left", "0px");
});
$('#slide').mouseout(function() {
$("#slide").css("left", "-150px");
});
});
</script>
Run Code Online (Sandbox Code Playgroud)
Sac*_*tte 10
你需要animate()方法 -
var width = $('#slide').width() - 10;
$('#slide').hover(function () {
$(this).stop().animate({left:"0px"},500);
},function () {
$(this).stop().animate({left: - width },500);
});
Run Code Online (Sandbox Code Playgroud)
我以前加.stop()过这里.这将清除由于快速移动鼠标而构建的动画队列.