【问题标题】:jQuery UI make the effect less abrupt and jerkyjQuery UI 使效果不那么突兀和生涩
【发布时间】:2013-06-04 15:22:25
【问题描述】:

我有一个小切换侧边栏,我正在使用 jQuery UI。问题是这是非常生涩的行为。不管怎样,它看起来像一个平滑的左右滚动吗?

我试图让外壳像内部容器滑动一样顺畅滑动。目前,一旦内部 div 完成缓动,它就会捕捉。

$(".snapper").click(function() {
 $(".sidebar-wrapper").toggle("slide", { direction: "right" }, 1000);
 $("#sidebar").css("width" , "auto");
});

在线示例。 http://frontendtrends.com/sidebar/

【问题讨论】:

  • jQuery 切换动画卡顿的原因通常是由于 jQuery 错误计算了目标宽度/高度。计算是通过将元素放置在模仿父元素的虚拟元素中并将其设为display: block 来完成的。如果父元素或您正在滑动的元素没有定义的宽度/高度,jQuery 可能会错误地将其计算为小于或大于应有的值。元素和/或其父元素上的填充和边距也可能导致此问题。
  • 我为两个容器定义了宽度,当#sidebar 捕捉时它仍然可以简化内容。

标签: jquery jquery-ui css


【解决方案1】:

问题在于auto。将其更改为某个固定值,您就完成了。

$("#sidebar").css("width" , "200px");

查看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);
    }
  });
  });

【讨论】:

  • 我在css中设置了宽度。不过,我继续尝试了您的更改,它只是使侧边栏变小了,但仍然很生涩。
  • 你能发布 jsbin.com 链接来模拟你的问题吗?
  • @ndesign11 我认为他的意思是您解决问题后将存在的示例。
  • @ndesign11 查看演示。
猜你喜欢
  • 2018-07-09
  • 2013-03-02
  • 1970-01-01
  • 1970-01-01
  • 2018-08-10
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多