固定位置Jquery上的Easing



是否有任何方法可以为固定元素添加缓和?,我一直在四处寻找,却找不到答案。我真的不知道会是什么样子,也许是。。。

$(window).scroll(function() { 
    $("#form").animate({position:"fixed", easing: 'swing'});
});

任何帮助都将不胜感激^^谢谢!

编辑:我想要的是,当用户滚动时,固定元素显然会跟随窗口位置,但我想添加的是,与具有缓和效果的滚动操作相比,有一点延迟。

您必须使该div绝对定位、z索引且没有父级,然后在滚动事件上移动它。您可以知道使用scrollTop()滚动的像素数。类似这样的东西:

  $(window).scroll(function(){ 
     var offset=100;
     //stop is called so easing doesn't affect while it is still scrolling.
     $("form").stop().animate({top:($(window).scrollTop()+offset)+"px"}, 300, 'swing');
  });

试试这个:

$("#form").animate({position:"fixed"}, 300, 'swing');

从jQuery api(http://api.jquery.com/animate/):

jQuery库中唯一的宽松实现是默认的,称为挥杆,以恒定的速度前进,称为线性的使用插件可以获得更多的放松功能,最引人注目的是jQuery UI套件。

$("form").animate({position:"fixed"}, 300, 'swing'); //swing being default

最新更新