jQuery UI make the effect less abrupt and jerky

随声附和 提交于 2020-01-07 03:39:22

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!