[英]Jquery waypoints with smooth scroll
I am having a little trouble with JQuery waypoints here. 我在这里使用JQuery航点有点麻烦。 Im using it for my auto scroll navigation on my one page site: 我在一页网站上将其用于自动滚动导航:
signaturestories.eu signaturestories.eu
It works fine when i use my scroll wheel. 当我使用滚轮时效果很好。 I need it to change the color of my nav items whenever a certain element reaches top of the screen. 每当某个元素到达屏幕顶部时,我都需要它来更改导航项的颜色。 The problem is when you press sign up --> about --> sign up, then is doesnt change the color that third time. 问题是当您按注册->关于->注册时,第三次没有改变颜色。
script.js: 的script.js:
$('a[href^="#"]').bind('click.smoothscroll',function (e) {
e.preventDefault();
var target = this.hash,
$target = $(target);
$('html, body').stop().animate({
'scrollTop': $target.offset().top-40
}, 900, 'swing', function () {
window.location.hash = target;
});
});
var currentMenuObject = '';
$('#wrapper').waypoint(function() {
$(currentMenuObject).css('color', '#f2e0bd');
currentMenuObject = '#top';
$(currentMenuObject).css('color', 'black');
}, { offset: '55'});
$('#introarticle').waypoint(function() {
$(currentMenuObject).css('color', '#f2e0bd');
currentMenuObject = '#top';
$(currentMenuObject).css('color', 'black');
}, { offset: '55'});
$('#signsection').waypoint(function() {
$(currentMenuObject).css('color', '#f2e0bd');
currentMenuObject = '#signup';
$(currentMenuObject).css('color', 'black');
}, { offset: '55'});
$('#storyarticle').waypoint(function() {
$(currentMenuObject).css('color', '#f2e0bd');
currentMenuObject = '#about';
$(currentMenuObject).css('color', 'black');
}, { offset: '55'});
You are calling this bit before adding jquery to page: 您在将jquery添加到页面之前正在调用此位:
$(document).ready(function(){
//jQuery code goes here and will be executed as soon as the page has finished loading
});
This throws an $ is not a function
error and stops executing code. 抛出$ is not a function
错误,并停止执行代码。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.