Javascript jQuery动画不在Firefox的IE中工作?

Javascript jQuery动画不在Firefox的IE中工作?,javascript,jquery,html,css,Javascript,Jquery,Html,Css,我有一个功能,我想水平滚动我的网页,我有以下功能在Chrome中运行良好,只是当我在Firefox和internetexplorer中测试它时,它会出错。有人能看到我的语法中有什么明显的错误吗 /* Navigtion */ $('nav ol li a').click(function(e){ e.preventDefault(); $('nav').find('.active').removeClass('active'); $(this).addClass('ac

我有一个功能,我想水平滚动我的网页,我有以下功能在
Chrome
中运行良好,只是当我在
Firefox
internetexplorer
中测试它时,它会出错。有人能看到我的语法中有什么明显的错误吗

/* Navigtion */
$('nav ol li a').click(function(e){
    e.preventDefault();
    $('nav').find('.active').removeClass('active'); 
    $(this).addClass('active'); 


    if( $(this).hasClass('sectionOne') ){

        scrollTo = $('.section-one').position().left;             
        $('body').animate({'scrollLeft': scrollTo}, 800);

    } else if( $(this).hasClass('sectionTwo') ){

        scrollTo = $('.section-two').position().left;             
        $('body').animate({'scrollLeft': scrollTo}, 800);

    } else if( $(this).hasClass('sectionThree') ){

        scrollTo = $('.section-three').position().left;             
        $('body').animate({'scrollLeft': scrollTo}, 800);

    } else if( $(this).hasClass('sectionFour') ){

        scrollTo = $('.section-four').position().left;             
        $('body').animate({'scrollLeft': scrollTo}, 800);

    } else if( $(this).hasClass('sectionFive') ){

        scrollTo = $('.section-five').position().left;             
        $('body').animate({'scrollLeft': scrollTo}, 800);

    } else if( $(this).hasClass('sectionSix') ){

        scrollTo = $('.section-six').position().left;             
        $('body').animate({'scrollLeft': scrollTo}, 800);

    } else if( $(this).hasClass('sectionSeven') ){

        scrollTo = $('.section-seven').position().left;             
        $('body').animate({'scrollLeft': scrollTo}, 800);

    }



});

不同的浏览器将滚动条附加到不同的元素,您必须这样做

$('html, body').animate({'scrollLeft': scrollTo}, 800);

尝试找出一种比所有那些if/else语句更好的方法,下面是一个示例

向定位添加数据属性

<nav>
   <ol>
      <li>
         <a data-section="section-one" ....

不同的浏览器将滚动条附加到不同的元素,您必须这样做

$('html, body').animate({'scrollLeft': scrollTo}, 800);

尝试找出一种比所有那些if/else语句更好的方法,下面是一个示例

向定位添加数据属性

<nav>
   <ol>
      <li>
         <a data-section="section-one" ....
尝试:

有些浏览器使用“html”,有些浏览器使用“body”

试试:

有些浏览器使用“html”,有些浏览器使用“body”