Hi everyone
I am implementing a simple smooth scrolling to next section type of thing.
Here is the code:
$('a.next-section').click(function(){
scrollTop = $(window).scrollTop();
$('h1').each(function(i, h1){ // loop through article headings
h1top = $(h1).offset().top; // get article heading top
if (scrollTop<h1top) { // compare if document is below heading
TweenLite.to(window, 0.5, {scrollTo:{y:h1top}, ease:Power2.easeOut});
return false; // exit function
}
});
});
As it is, it scrolls to the next section, but starts from the TOP of the page most of the time -
obviously I want it to scroll from the current window position to avoid the nasty 'massive jump' effect.
I have tried:
TweenLite.fromTo(window, 0.5, {y:window.y}, {scrollTo:{y:h1top}, ease:Power2.easeOut});
where 'window.y' is the current Y position of window (correct??)
I have also tried for the "from" part: {y:$(window).scrollTop()}
(or the "scrollTop" variable which is the same thing)
It does the same thing...
what am I missing?
It seems pretty simple...
Can anybody help me?
Thanks a lot (I'm learning)!