ace2296
says
I’m working with a multiple div ID parallax 3D effect. I tried it with this code once and it worked great, but now it’s giving me this error in the console ->
Uncaught TypeError: Cannot read property 'style' of null parallax.js:87 220Uncaught TypeError: Cannot read property 'style' of null parallax.js:79 295 Uncaught TypeError: Cannot read property 'style' of null parallax.js:79 moveDiv parallax.js:79 getMouseXY parallax.js:69 229Uncaught TypeError: Cannot read property 'style' of null parallax.js:79 17 Uncaught TypeError: Cannot read property 'style' of null parallax.js:79 moveDiv parallax.js:79 getMouseXY
Here is my parallax.js code
var verticalPosition;
var verticalPositionBefore;
var windowWidth = 960;
var windowHeight;
// Detect if the browser is IE or not.
// If it is not IE, we assume that the browser is NS.
var IE = document.all?true:false
// If NS -- that is, !IE -- then set up for mouse capture
if (!IE) document.captureEvents(Event.MOUSEMOVE)
// Set-up to use getMouseXY function onMouseMove
document.onmousemove = getMouseXY;
// Temporary variables to hold mouse x-y pos.s
var tempX = 0;
var tempY = 0;
var objectArray = new Array();
fillObjectArray();
positionDivs();
function fillObjectArray()
{
var ssplashesDiv = document.getElementById("ssplashes");
var ssplashesX = 312;
var ssplashesY = 33;
var ssplashesFactor = 0.05;
var ssplashesArray = new Array();
ssplashesArray.push(ssplashesDiv);
objectArray.push(ssplashesArray);
var msplashesDiv = document.getElementById("msplashes");
var msplashesX = 312;
var msplashesY = 33;
var msplashesFactor = 0.05;
var msplashesArray = new Array();
msplashesArray.push(msplashesDiv);
objectArray.push(msplashesArray);
var bsplashesDiv = document.getElementById("bsplashes");
var bsplashesX = 312;
var bsplashesY = 33;
var bsplashesFactor = 0.05;
var bsplashesArray = new Array();
bsplashesArray.push(bsplashesDiv);
objectArray.push(bsplashesArray);
}
// Main function to retrieve mouse x-y pos.s
function getMouseXY(e)
{
if (IE) { // grab the x-y pos.s if browser is IE
tempX = event.clientX + document.body.scrollLeft
tempY = event.clientY + document.body.scrollTop
} else { // grab the x-y pos.s if browser is NS
tempX = e.pageX
tempY = e.pageY
}
// catch possible negative values in NS4
if (tempX < 0){tempX = 0}
if (tempY < 0){tempY = 0}
moveDiv(tempX);
return true
}
function moveDiv(tempX)
{
for (var i=0;i<objectArray.length;i++)
{
var yourDivPositionX = objectArray[i][3] * (0.5 * windowWidth - tempX) + objectArray[i][1];
objectArray[i][0].style.left = yourDivPositionX + 'px';
}
}
function positionDivs()
{
for (var i=0;i<objectArray.length;i++)
{
objectArray[i][0].style.left = objectArray[i][1] + "px";
objectArray[i][0].style.top = objectArray[i][2] + "px";
}
}
The site is on my localhost so unfortunately I can’t provide a link.
Thanks
rongcon
says
you can’t get the object before you can get the style. I guess you store the options for each section in style of container. try to get container again!
