基于scrollTop()的自动滚动(auto scroll based on scrollTop())

我仍然试图抓住这些东西,所以一些帮助将不胜感激

我有5个div的所有设置高度基于$(窗口)。高度() 我已为每个div设置了唯一的ID

我有一些变量

var wH = $(window).height(); var half-wH = (wH) / 2;

我想做的是让查询滚动窗口到每个ID基于50%的window.height无论哪种方式

即窗口高度600px 小于300px scrollTo#id1 大于300px但小于900px scrollTo#id2 等等,但只是经过一小段时间后

我知道,如果我使用 .scrollTop()与第1个div#ID1组合使用 它会显示从我页面顶部滚动的像素

我怎么把它放在一起让我挠头!

i'm still trying to grasp this stuff so some help would be appreciated

I have 5 div's all set with heights based off $(window).height() I have set each div with a unique ID

i have some vars set

var wH = $(window).height(); var half-wH = (wH) / 2;

what i would like to do would be to have query scroll the window to each ID based on 50% of window.height either way

i.e. window height 600px less than 300px scrollTo #id1 greater then 300px but less than 900px scrollTo #id2 etc. but only after a small delay

I know that if i use .scrollTop() in combination with the 1st div #ID1 it'll show me the pixels scrolled from the top of my page

how i place it all together has me scratching my head!!

最满意答案

var st = $(window).scrollTop(); var elem = $('#id1').offset().top; var elem2 = $('#id2').offset().top; if(st < 300) { $(window).scrollTop(elem) } if(st > 300 && st < 900) { $(window).scrollTop(elem2) } var st = $(window).scrollTop(); var elem = $('#id1').offset().top; var elem2 = $('#id2').offset().top; if(st < 300) { $(window).scrollTop(elem) } if(st > 300 && st < 900) { $(window).scrollTop(elem2) }基于scrollTop()的自动滚动(auto scroll based on scrollTop())

我仍然试图抓住这些东西,所以一些帮助将不胜感激

我有5个div的所有设置高度基于$(窗口)。高度() 我已为每个div设置了唯一的ID

我有一些变量

var wH = $(window).height(); var half-wH = (wH) / 2;

我想做的是让查询滚动窗口到每个ID基于50%的window.height无论哪种方式

即窗口高度600px 小于300px scrollTo#id1 大于300px但小于900px scrollTo#id2 等等,但只是经过一小段时间后

我知道,如果我使用 .scrollTop()与第1个div#ID1组合使用 它会显示从我页面顶部滚动的像素

我怎么把它放在一起让我挠头!

i'm still trying to grasp this stuff so some help would be appreciated

I have 5 div's all set with heights based off $(window).height() I have set each div with a unique ID

i have some vars set

var wH = $(window).height(); var half-wH = (wH) / 2;

what i would like to do would be to have query scroll the window to each ID based on 50% of window.height either way

i.e. window height 600px less than 300px scrollTo #id1 greater then 300px but less than 900px scrollTo #id2 etc. but only after a small delay

I know that if i use .scrollTop() in combination with the 1st div #ID1 it'll show me the pixels scrolled from the top of my page

how i place it all together has me scratching my head!!

最满意答案

var st = $(window).scrollTop(); var elem = $('#id1').offset().top; var elem2 = $('#id2').offset().top; if(st < 300) { $(window).scrollTop(elem) } if(st > 300 && st < 900) { $(window).scrollTop(elem2) } var st = $(window).scrollTop(); var elem = $('#id1').offset().top; var elem2 = $('#id2').offset().top; if(st < 300) { $(window).scrollTop(elem) } if(st > 300 && st < 900) { $(window).scrollTop(elem2) }