How come this works:

```
$(document).ready(function(){
docReady();
});
var docReady = function(){
if($('.page').length > 0){
sideScroll();
}
}
var sideScroll = function(){
var $bl = $(".grid-wrapper"),
$th = $(".grid"),
blW = $bl.outerWidth(),
blSW = $bl[0].scrollWidth,
wDiff = (blSW/blW)-1, // widths difference ratio
mPadd = 60, // Mousemove Padding
damp = 20, // Mousemove response softness
mX = 0, // Real mouse position
mX2 = 0, // Modified mouse position
posX = 0,
mmAA = blW-(mPadd*2), // The mousemove available area
mmAAr = (blW/mmAA); // get available mousemove fidderence ratio
$bl.mousemove(function(e) {
mX = e.pageX - this.offsetLeft;
mX2 = Math.min( Math.max(0, mX-mPadd), mmAA ) * mmAAr;
});
setInterval(function(){
posX += (mX2 - posX) / damp; // zeno's paradox equation "catching delay"
$th.css({
"-webkit-transform": "translate3d(" + -posX*wDiff +"px,0,0)",
"-moz-transform": "translate3d(" + -posX*wDiff +"px,0,0)",
"transform": "translate3d(" + -posX*wDiff +"px,0,0)"
});
}, 10);
}
```

but this don’t, it gives me “Uncaught TypeError: Cannot read property ‘scrollWidth’ of undefined”.

```
var myPage = $('.page').length > 0;
$(document).ready(function(){
docReady();
});
var docReady = function(){
if(myPage){
sideScroll();
}
}
var sideScroll = function(){
var $bl = $(".grid-wrapper"),
$th = $(".grid"),
blW = $bl.outerWidth(),
blSW = $bl[0].scrollWidth,
wDiff = (blSW/blW)-1, // widths difference ratio
mPadd = 60, // Mousemove Padding
damp = 20, // Mousemove response softness
mX = 0, // Real mouse position
mX2 = 0, // Modified mouse position
posX = 0,
mmAA = blW-(mPadd*2), // The mousemove available area
mmAAr = (blW/mmAA); // get available mousemove fidderence ratio
$bl.mousemove(function(e) {
mX = e.pageX - this.offsetLeft;
mX2 = Math.min( Math.max(0, mX-mPadd), mmAA ) * mmAAr;
});
setInterval(function(){
posX += (mX2 - posX) / damp; // zeno's paradox equation "catching delay"
$th.css({
"-webkit-transform": "translate3d(" + -posX*wDiff +"px,0,0)",
"-moz-transform": "translate3d(" + -posX*wDiff +"px,0,0)",
"transform": "translate3d(" + -posX*wDiff +"px,0,0)"
});
}, 10);
}
```

Shouldn’t the variable be considered a global variable, thus working everywhere? What am I missing?