Javascript 平滑固定浮动
我为你创造了一个精神层面 我使用了这个想法,但试图将其限制在管道领域。这并不完美,但这一页的短小有助于它 如何使其更平滑,尤其是在缓慢滚动时? 而且,当我用iPhone滚动时,它会工作,但只有在我完成滚动之后,而不是在我滚动的时候。这只是iPhone滚动机制的一个限制,还是有办法解决这个问题 这个: placeBubble函数:Javascript 平滑固定浮动,javascript,jquery,html,css,positioning,Javascript,Jquery,Html,Css,Positioning,我为你创造了一个精神层面 我使用了这个想法,但试图将其限制在管道领域。这并不完美,但这一页的短小有助于它 如何使其更平滑,尤其是在缓慢滚动时? 而且,当我用iPhone滚动时,它会工作,但只有在我完成滚动之后,而不是在我滚动的时候。这只是iPhone滚动机制的一个限制,还是有办法解决这个问题 这个: placeBubble函数: function placeBubble(first_time) { scrollDepth = $(document).scrollTop(); if
function placeBubble(first_time)
{
scrollDepth = $(document).scrollTop();
if(first_time)
{
$('#bubble').css('top', center + 'px');
}
temp = ((center - (scrollDepth - orig_scrollDepth))/viewport_h)*100;
$('#bubble').css('top', (temp<-50?-50:(temp>50?50:temp)) +'%')
.animate(
{top: (center/viewport_h)*100+'%'},
{duration:800,queue:false},
{
step: function(now, fx) {
//this is never called, don't know why
alert(now);
}
}, function(){
/*
Should I do the following?
orig_scrollDepth = $(document).scrollTop();*/
});
/*Without the next line, the bubble slides down from the top of the
tube on any length scroll in any direction*/
orig_scrollDepth = $(document).scrollTop();
}
}
编辑:
哇,我刚用三星Galaxy S1标准网络浏览器检查过。卷尺的z向分度和绝对定位出现了灾难性的失败。为什么会这样 也许你对.css的使用让它变得神经质了。animate可能是一个合适的替代品,具有非常快的设置,使其平滑地滑动到临时起始位置,然后缓慢地滑动回到中心位置
$('#bubble').animate({'top': (temp<-50?-50:(temp>50?50:temp)) +'%'},{duration:200})
.animate( [...]
当然谢谢您是否有理由选择固定值200?备选方案可能包括要设置的最高值的系数4*Math.abs最高值是什么,也就是说,0-200和旅行距离的一个因素,即当前和目的地之间的差异:Math.abswhat-the-top-value-is-being-set-to-current-top-value+50/0.5我想这是你需要玩的类型,直到你喜欢结果为止,所以这个数字在发布时对我来说并不重要。酷。你是对的;我只是做了一些测试,第一个选择让它再次紧张起来。我可能需要看看真正的精神关卡是怎么做的,因为例如,如果你上下滚动很多次,那么在你停下来后,它会引发一长串的动画,我甚至不应该担心有人会这样做,但是:
function placeBubble(first_time)
{
scrollDepth = $(document).scrollTop();
if(first_time)
{
$('#bubble').css('top', center + 'px');
}
temp = ((center - (scrollDepth - orig_scrollDepth))/viewport_h)*100;
$('#bubble').css('top', (temp<-50?-50:(temp>50?50:temp)) +'%')
.animate(
{top: (center/viewport_h)*100+'%'},
{duration:800,queue:false},
{
step: function(now, fx) {
//this is never called, don't know why
alert(now);
}
}, function(){
/*
Should I do the following?
orig_scrollDepth = $(document).scrollTop();*/
});
/*Without the next line, the bubble slides down from the top of the
tube on any length scroll in any direction*/
orig_scrollDepth = $(document).scrollTop();
}
}
$('#bubble').animate({'top': (temp<-50?-50:(temp>50?50:temp)) +'%'},{duration:200})
.animate( [...]