Skip to content

Commit

Permalink
perf improvements, use strict
Browse files Browse the repository at this point in the history
  • Loading branch information
hakimel committed Apr 21, 2012
1 parent 1410928 commit 34b674b
Show file tree
Hide file tree
Showing 5 changed files with 32 additions and 28 deletions.
File renamed without changes.
File renamed without changes.
4 changes: 2 additions & 2 deletions index.html
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
<link href='http://fonts.googleapis.com/css?family=Lato:400,700,400italic,700italic' rel='stylesheet' type='text/css'>

<link rel="stylesheet" href="css/example.css">
<link rel="stylesheet" href="css/stroll-1.0.css">
<link rel="stylesheet" href="css/stroll.css">
</head>

<body>
Expand Down Expand Up @@ -82,7 +82,7 @@ <h2>Twirl (CSS 3D)</h2>
</article>
</div>

<script src="js/stroll-1.0.js"></script>
<script src="js/stroll.js"></script>
<script>
Stroll.bind( '#main ul' );
</script>
Expand Down
56 changes: 30 additions & 26 deletions js/stroll-1.0.js → js/stroll.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
/*!
* stroll.js - CSS scrolling effects
* stroll.js - CSS scroll effects
* http://lab.hakim.se/scroll-effects
* MIT licensed
*
* Created by Hakim El Hattab, http://hakim.se
*/
(function(){

"use strict";

// All of the lists that are currently bound
var lists = [];

Expand Down Expand Up @@ -58,14 +60,14 @@
domElement: list,

// Apply past/future classes to list items outside of the viewport
update: function() {
update: function( force ) {
var scrollTop = list.pageYOffset || list.scrollTop,
scrollBottom = scrollTop + listHeight;

// Quit if nothing changed
if( scrollTop !== list.lastTop ) {
list.lastTop = scrollTop;

// One loop to make our changes to the DOM
for( var i = 0, len = items.length; i < len; i++ ) {
var item = items[i];
Expand Down Expand Up @@ -141,13 +143,6 @@
return false;
};

/**
* Checks if the client is capable of running the library.
*/
function isCapable() {
return !!document.body.classList;
};

/**
* Calls 'method' for each DOM element discovered in
* 'target'.
Expand All @@ -157,18 +152,20 @@
* @param method A function to call for each element target
*/
function batch( target, method ) {
var i, len;

// Selector
if( typeof target === 'string' ) {
var targets = document.querySelectorAll( target );

for( j = 0; j < targets.length; j++ ) {
method.call( null, targets[j] );
for( i = 0, len = targets.length; i < len; i++ ) {
method.call( null, targets[i] );
}
}
// Array (jQuery)
else if( typeof target === 'object' && typeof target.length === 'number' ) {
for( j = 0; j < target.length; j++ ) {
method.call( null, target[j] );
for( i = 0, len = target.length; i < len; i++ ) {
method.call( null, target[i] );
}
}
// Single element
Expand All @@ -180,6 +177,13 @@
}
};

/**
* Checks if the client is capable of running the library.
*/
function isCapable() {
return !!document.body.classList;
};

/**
* Public API
*/
Expand All @@ -203,15 +207,15 @@
}
};

})();

window.requestAnimFrame = (function(){
return window.requestAnimationFrame ||
window.webkitRequestAnimationFrame ||
window.mozRequestAnimationFrame ||
window.oRequestAnimationFrame ||
window.msRequestAnimationFrame ||
function( callback ){
window.setTimeout(callback, 1000 / 60);
};
})();
window.requestAnimFrame = (function(){
return window.requestAnimationFrame ||
window.webkitRequestAnimationFrame ||
window.mozRequestAnimationFrame ||
window.oRequestAnimationFrame ||
window.msRequestAnimationFrame ||
function( callback ){
window.setTimeout(callback, 1000 / 60);
};
})();

})();
File renamed without changes.

0 comments on commit 34b674b

Please sign in to comment.