Javascript Jquery scrollTo不';我不能在Firefox上工作

Javascript Jquery scrollTo不';我不能在Firefox上工作,javascript,jquery,firefox,scrollto,Javascript,Jquery,Firefox,Scrollto,我正在使用scrollTo-1.4.3.1。插件到选定的菜单项,这在Chrome上非常有效,但在Firefox上则完全相反。有人能告诉我为什么Firefox会出现这种情况,我该如何解决 JS: $(文档).ready(函数(e){ var lastId, topMenu=$(“.main导航”), topMenuHeight=topMenu.outerHeight()+15, //所有列表项 menuItems=topMenu.find(“a”), //与菜单项相对应的锚定 scrollIte

我正在使用scrollTo-1.4.3.1。插件到选定的菜单项,这在Chrome上非常有效,但在Firefox上则完全相反。有人能告诉我为什么Firefox会出现这种情况,我该如何解决

JS:


$(文档).ready(函数(e){
var lastId,
topMenu=$(“.main导航”),
topMenuHeight=topMenu.outerHeight()+15,
//所有列表项
menuItems=topMenu.find(“a”),
//与菜单项相对应的锚定
scrollItems=menuItems.map(函数(){
var item=$($(this.attr(“href”));
if(item.length){return item;}
});         
菜单项。单击(函数(e){
var项目=$('main nav li a');
var lastItem=$('.main nav li a:last');
var指数=项目。指数(最后一个项目);
//警报(项目);
var href=$(this.attr(“href”),
offsetTop=href==“#”?0:$(href).offset()。顶部菜单高度+1;
如果(href==“#联系部分”){
$('html,body').stop().animate({
滚动顶部:偏移量+600
}“慢”);
}
其他的
$('html,body').stop().animate({
滚动顶:偏置
}“慢”);
e、 预防默认值();
});
});
还有我的HTML

<ul class="main-nav">
                    <li>
                        <a href="#portfolio" id="toTop">Client Portfolio</a>
                    </li>
                    <li>
                        <a href="#service-provided" id="toService">Service Provided</a>
                    </li>
                    <li>
                        <a href="#team-section" id="toTeam">Our Team</a>
                    </li>
                    <li>
                        <a href="#contact-section" id="toContact">Contact Us</a>
                    </li>
                </ul>
也许可以尝试以下脚本:

//缓存选择器
var lastId,
topMenu=$(“#top menu”),
topMenuHeight=topMenu.outerHeight()+15,
//所有列表项
menuItems=topMenu.find(“a”),
//与菜单项相对应的锚定
scrollItems=menuItems.map(函数(){
var item=$($(this.attr(“href”));
if(item.length){return item;}
});
//将单击处理程序绑定到菜单项
//所以我们可以得到一个奇特的卷轴动画
菜单项。单击(函数(e){
var href=$(this.attr(“href”),
offsetTop=href==“#”?0:$(href).offset()。顶部菜单高度+1;
$('html,body').stop().animate({
滚动顶:偏置
}, 300);
e、 预防默认值();
});
//绑定到滚动
$(窗口)。滚动(函数(){
//获取容器滚动位置
var fromTop=$(this.scrollTop()+topMenuHeight;
//获取当前滚动项目的id
var cur=scrollItems.map(函数(){
if($(this).offset().top
试试这个:

change html,body as window

    $('window').stop().animate({         
                      scrollTop: offsetTop+600
                  }, "slow");

完美工作的对立面到底是什么?你需要详细说明每个浏览器中发生了什么,它在Firefox中应该做什么,等等。@AnthonyGrist“完美工作”的反面根本不起作用。这意味着,当我从菜单中单击一个项目时,slideTo脚本无法完成本应完成的工作(滚动到div)问题仍然存在,代码在chrome上运行良好,但在Firefox上不起作用小提琴也不起作用?也许你的firefox有问题?多年以来,它在每一款浏览器中都适用——所有版本。
  // Cache selectors
    var lastId,
    topMenu = $("#top-menu"),
    topMenuHeight = topMenu.outerHeight()+15,
    // All list items
    menuItems = topMenu.find("a"),
    // Anchors corresponding to menu items
    scrollItems = menuItems.map(function(){
      var item = $($(this).attr("href"));
      if (item.length) { return item; }
    });

    // Bind click handler to menu items
    // so we can get a fancy scroll animation
    menuItems.click(function(e){
    var href = $(this).attr("href"),
      offsetTop = href === "#" ? 0 : $(href).offset().top-topMenuHeight+1;
    $('html, body').stop().animate({ 
      scrollTop: offsetTop
    }, 300);
    e.preventDefault();
    });

    // Bind to scroll
    $(window).scroll(function(){
    // Get container scroll position
    var fromTop = $(this).scrollTop()+topMenuHeight;

    // Get id of current scroll item
    var cur = scrollItems.map(function(){
     if ($(this).offset().top < fromTop)
       return this;
    });
    // Get the id of the current element
    cur = cur[cur.length-1];
    var id = cur && cur.length ? cur[0].id : "";

    if (lastId !== id) {
       lastId = id;
       // Set/remove active class
       menuItems
         .parent().removeClass("active")
         .end().filter("[href=#"+id+"]").parent().addClass("active");
   }                   
   });
change html,body as window

    $('window').stop().animate({         
                      scrollTop: offsetTop+600
                  }, "slow");