我的主屏幕上有一些动画通过我在Angular.cli.json文件中的脚本数组中包含的外部javascript文件。在实现到我的项目的路由以使用多个页面后,动画不再在页面加载时执行。现在我实现了路由,是否必须更改我的javascript引用方式?这是我的脚本数组供参考:
"scripts": [
"./assets/build/js/vendor/jquery-1.11.2.min.js",
"./assets/build/js/plugins.js",
"./assets/build/js/vendor/modernizr-2.8.3.min.js",
"./assets/build/js/main.js"
]
编辑: 这是我的javascript
var didScroll;
var lastScrollTop = 0;
var delta = 5;
var navbarHeight = $('.wrp-site-header').outerHeight();
$(window).scroll(function(event){
didScroll = true;
});
setInterval(function() {
if (didScroll) {
hasScrolled();
didScroll = false;
}
}, 250);
function hasScrolled() {
var st = $(this).scrollTop();
// Make sure they scroll more than delta
if(Math.abs(lastScrollTop - st) <= delta)
return;
// If they scrolled down and are past the navbar, add class .nav-up.
// This is necessary so you never see what is "behind" the navbar.
if (st > lastScrollTop && st > navbarHeight){
// Scroll Down
$('.wrp-site-header').removeClass('nav-down').addClass('nav-up');
} else {
// Scroll Up
if(st + $(window).height() < $(document).height()) {
$('.wrp-site-header').removeClass('nav-up').addClass('nav-down');
}
}
lastScrollTop = st;
}