问题
I have a little toggle sidebar that I am using jQuery UI. The problem is it is very jerky behavior. Anyway to may it look like a smooth scroll left/right?
I am trying to get the outer shell to slide smoothly like the inner container slides. Currently it is snapping once the inner div is finished easing.
$(".snapper").click(function() {
$(".sidebar-wrapper").toggle("slide", { direction: "right" }, 1000);
$("#sidebar").css("width" , "auto");
});
Online Example. http://frontendtrends.com/sidebar/
回答1:
The problem is with auto
. change it to some fix value and you are done.
$("#sidebar").css("width" , "200px");
Check this Demo
CSS
.o{
display:block;
float:right;
width:30px;
border-radius:10px;
height:300px;
overflow:hidden;
background-color:black;
}
.out{
display:block;
float:right;
width:40%;
border-radius:10px;
height:300px;
background-color:black;
}
.i{
display:none;
width:200px;
border-radius:10px;
height:200px;
overflow:hidden;
background-color:grey;
margin:10px 50px 10px 10px;
}
.i2{
display:block;
width:100px;
border-radius:10px;
height:100px;
background-color:orange;
margin:10px 50px 10px 10px;
}
JS
$(document).ready(function(){
$('.o').click(function(){
$(this).toggleClass('out',1000);
if ($('.i').css('display')=='block'){
$('.i').fadeOut('slow');
}
else{
$('.i').fadeIn(1000);
}
});
});
来源:https://stackoverflow.com/questions/16902824/jquery-ui-make-the-effect-less-abrupt-and-jerky