我在我的 html 页面中使用了一个 java 脚本。现在我将脚本移动到一个外部 js 文件中。这是脚本(jful.js)
<script type="text/javascript">
$(function() {
// grab the initial top offset of the navigation
var sticky_navigation_offset_top = $('#catnav').offset().top;
// our function that decides weather the navigation bar should have "fixed" css position or not.
var sticky_navigation = function(){
var scroll_top = $(window).scrollTop(); // our current vertical position from the top
// if we've scrolled more than the navigation, change its position to fixed to stick to top,
// otherwise change it back to relative
if (scroll_top > sticky_navigation_offset_top) {
$('#catnav').css({ 'position': 'fixed', 'top':0, 'left':0 });
} else {
$('#catnav').css({ 'position': 'relative' });
}
};
// run our function on load
sticky_navigation();
// and run it again every time you scroll
$(window).scroll(function() {
sticky_navigation();
});
});
</script>
现在脚本不工作了。我包括这样的脚本
<head><script src="http://ajax.googleapis.com/ajax/libs/jquery/1.6.4/jquery.min.js"></script>
<script type="text/javascript" src="jful.js"></script></head>
当我再次将脚本直接添加到 HTML 文档时,它可以工作!(当我们向下滚动页面时执行此脚本)有什么问题?