I have made an top menu with underneith the buttons a little arrow. I want this arrow to move correspoing to where the scroll is on my one page design.
I think i got the basics working... but somehow it keeps flippin around as soon as i try to animate the arrow (instead of making it jump between buttons). I guess it has something to do with the multiple >=... but i can't think of an alternative. Can anyone please give me some advice?
The effect can be seen here: http://www.lightwavedesign.nl/
The JS i am using is as follow:
function goToByScroll(id){
$('html,body').animate({scrollTop: $("#"+id).offset().top-78},'1000');
};
window.onload = function() {
var link1 = $("#Welkom"); var positionLink1 = link1.position();
var link2 = $("#OverMij"); var positionLink2 = link2.position();
var link3 = $("#Portfolio"); var positionLink3 = link3.position();
var link4 = $("#Contact"); var positionLink4 = link4.position();
function getScrollTop() {
if (typeof window.pageYOffset !== 'undefined' ) {return window.pageYOffset;}
var d = document.documentElement;
if (d.clientHeight) {return d.scrollTop;}
return document.body.scrollTop;
}
window.onscroll = function() {
var box = document.getElementById('menuAanwijzer'),
scroll = getScrollTop();
if (scroll <= positionLink2.top) {$('#menuAanwijzer').animate({left: '665px'}, 100)}
if (scroll >= positionLink2.top-80) {$('#menuAanwijzer').animate({left: '760px'}, 100)}
if (scroll >= positionLink3.top-80) {$('#menuAanwijzer').animate({left: '860px'}, 100)}
if (scroll >= positionLink4.top-80) {$('#menuAanwijzer').animate({left: '960px'}, 100)}
if (scroll >= positionLink2.top-80) {$('#menuTitel').fadeIn('500');}
if (scroll <= positionLink2.top-80) {$('#menuTitel').fadeOut('500');}
};
};
Simple, clear your animation queue using .stop()
.stop().animate()
if (scroll <= positionLink2.top) {$('#menuAanwijzer').stop().animate({left: '665px'}, 100)}
if (scroll >= positionLink2.top-80) {$('#menuAanwijzer').stop().animate({left: '760px'}, 100)}
if (scroll >= positionLink3.top-80) {$('#menuAanwijzer').stop().animate({left: '860px'}, 100)}
if (scroll >= positionLink4.top-80) {$('#menuAanwijzer').stop().animate({left: '960px'}, 100)}
if (scroll >= positionLink2.top-80) {$('#menuTitel').stop().fadeIn('500');}
if (scroll <= positionLink2.top-80) {$('#menuTitel').stop().fadeOut('500');}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With