Javascript 滚动脚本实现不需要';行不通

Javascript 滚动脚本实现不需要';行不通,javascript,jquery,html,css,scroll,Javascript,Jquery,Html,Css,Scroll,我正在尝试实现这把小提琴的代码: HTML-------------------------------------------------------------------- 由于某种原因,它不起作用。我的错在哪里?我已经看了好几遍了,但现在真的应该可以用了 提前非常感谢。您需要添加jquery。最初的fiddle中加载了jQuery1.64。如果你把它加进去,它会工作的 var topRange=200,//从视口顶部测量到向下X像素 edgeMargin=20,//页眉上方的边距或

我正在尝试实现这把小提琴的代码:

HTML--------------------------------------------------------------------

由于某种原因,它不起作用。我的错在哪里?我已经看了好几遍了,但现在真的应该可以用了


提前非常感谢。

您需要添加jquery。最初的fiddle中加载了jQuery1.64。如果你把它加进去,它会工作的

var topRange=200,//从视口顶部测量到向下X像素
edgeMargin=20,//页眉上方的边距或页尾的边距
animationTime=1200,//以毫秒为单位的时间
contentTop=[];
$(文档).ready(函数(){
//如果用户执行某些操作,请停止动画滚动
$('html,body').bind('scroll mousedown DOMMouseScroll mouseweelkeyup',函数(e){
如果(e.which>0 | | e.type=='mousedown'| | e.type=='mouseweel'){
$('html,body').stop();
}
})
//将内容设置为一组位置
$('.da')。查找('a')。每个(函数(){
push($($(this.attr('href')).offset().top);
})
//“动画”菜单滚动到内容
$('.da')。查找('a')。单击(函数(){
var sel=这个,
newTop=Math.min(contentTop[$('.da a').index($(this)),$(document.height()-$(window.height());//如果位于文档底部,则获取内容顶部或顶部位置
$('html,body').stop().animate({'scrollTop':newTop},animationTime,function(){
window.location.hash=$(sel.attr('href');
});
返回false;
})
//调整侧菜单
$(窗口)。滚动(函数(){
var winTop=$(窗口).scrollTop(),
bodyHt=$(文档).height(),
vpHt=$(窗口).height()+边缘边缘;//视口高度+边距
$。每个(contentTop,函数(i,loc){
如果((loc>winTop-edgeMargin&&(loc=bodyHt))){
$('.da').removeClass('current').eq(i).addClass('current');
}
})
})
});
.da{
位置:固定;
z指数:2;
}
.da.current.da.current:悬停{
背景色:#000;
}
.db{
}

第一组
第二组
第三组
第四组

我以为我已经实现了它?我把它改成了jquery 1.6.4它仍然不起作用(从你的网站来看,它工作得非常完美。请接受mu answerI的测试。我在Chrome、Firefox和Safari中测试了它-从我的角度来看,它没有。既没有动画也没有导航标记。我还实现了jquery?!它应该工作,我测试了Chrome b4 Chrome的vsn
HTML --------------------------------------------------------------------

<div class="da">
    <a href="#diva" class="current">DIV1</a>
    <a href="#divb">DIV2</a>
    <a href="#divc">DIV3</a>
    <a href="#divd">DIV4</a>
</div>
<div class="db">
    <div style="width: 300px; height: 300px; background-color: #996633"><a id="diva" name="diva">DIV1</a></div>
    <div style="width: 300px; height: 300px; background-color: #CC0066"><a id="divb" name="divb">DIV2</a></div>
    <div style="width: 300px; height: 300px; background-color: #3300FF"><a id="divc" name="divc">DIV3</a></div>
    <div style="width: 300px; height: 300px; background-color: #99CC00"><a id="divd" name="divd">DIV4</a></div>
</div>




JS --------------------------------------------------------------------

    var topRange      = 200,  // measure from the top of the viewport to X pixels down
     edgeMargin    = 20,   // margin above the top or margin from the end of the page
     animationTime = 1200, // time in milliseconds
     contentTop = [];

$(document).ready(function(){
 // Stop animated scroll if the user does something
$('html,body').bind('scroll mousedown DOMMouseScroll mousewheel keyup', function(e){
  if ( e.which > 0 || e.type == 'mousedown' || e.type == 'mousewheel' ){
    $('html,body').stop();
  }
})

 // Set up content an array of locations
$('.da').find('a').each(function(){
  contentTop.push( $( $(this).attr('href') ).offset().top );
})

 // Animate menu scroll to content
$('.da').find('a').click(function(){
  var sel = this,
  newTop = Math.min( contentTop[ $('.da a').index( $(this) ) ], $(document).height() - $(window).height() ); // get content top or top position if at the document bottom
  $('html,body').stop().animate({ 'scrollTop' : newTop }, animationTime, function(){
    window.location.hash = $(sel).attr('href');
  });
  return false;
})

 // adjust side menu
$(window).scroll(function(){
  var winTop = $(window).scrollTop(),
  bodyHt = $(document).height(),
  vpHt = $(window).height() + edgeMargin;  // viewport height + margin
  $.each( contentTop, function(i,loc){
    if ( ( loc > winTop - edgeMargin && ( loc < winTop + topRange || ( winTop + vpHt ) >= bodyHt ) ) ){
      $('.da a').removeClass('current').eq(i).addClass('current');
    }
  })
})

});




CSS --------------------------------------------------------------------

    .da{
  position:fixed;
  z-index: 2;
}
.da .current,.da .current:hover{
  background-color: #000;
}
.db{
}