offsetTop-taro007

JavaScript performance comparison

Test case created by 祁涛

Info

var scrollTop = $window.scrollTop();

vs

scrollTop = document.body.scrollTop + document.documentElement.scrollTop;

Preparation code

<script src="//ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js"></script>
 
<script>
Benchmark.prototype.setup = function() {
    var $window = $( 'window' );
    var scrollTop;
    var docElem = document.documentElement;
    var docBody = document.body;
};
</script>

Preparation code output

Test runner

Warning! For accurate results, please disable Firebug before running the tests. (Why?)

Java applet disabled.

Testing in unknown unknown
Test Ops/sec
jQuery style
var scrollTop = $window.scrollTop();
pending…
javascript style
scrollTop = docBody.scrollTop + docElem.scrollTop;
pending…

You can edit these tests or add even more tests to this page by appending /edit to the URL.

Compare results of other browsers

0 comments

Add a comment