如题

解决方案 »

  1.   

    var top = document.body.scrollTop | document.documentElement.scrollTop;
      

  2.   

    var top = document.body.scrollTop | document.documentElement.scrollTop;
    是这两个其中的一个,看你的html用什么规范。
      

  3.   

    var top = document.body.scrollTop || document.documentElement.scrollTop;
      

  4.   

    jQuery.each( ["Left", "Top"], function( i, name ) {
    var method = "scroll" + name; jQuery.fn[ method ] = function(val) {
    var elem = this[0], win;

    if ( !elem ) {
    return null;
    } if ( val !== undefined ) {
    // Set the scroll offset
    return this.each(function() {
    win = getWindow( this ); if ( win ) {
    win.scrollTo(
    !i ? val : jQuery(win).scrollLeft(),
     i ? val : jQuery(win).scrollTop()
    ); } else {
    this[ method ] = val;
    }
    });
    } else {
    win = getWindow( elem ); // Return the scroll offset
    return win ? ("pageXOffset" in win) ? win[ i ? "pageYOffset" : "pageXOffset" ] :
    jQuery.support.boxModel && win.document.documentElement[ method ] ||
    win.document.body[ method ] :
    elem[ method ];
    }
    };
    });