Hi all,
Here is a little function I created that calculates the mid-point of any element and then calls for actions when you move over and around the element. Can be adapted for most situations.
Run this code as a new function on Mouse Over
/// instansiate the element and any other elements at the initial mouseover
element.style.transform = "rotateX(0deg) rotateY(0deg) rotateZ(0deg) scale3d(1.07, 1.07, 1.07)";
hypeDocument.getElementById('text').style.transform = "";
element.style.boxShadow = "0px 5px 10px #666";
element.style.borderRadius = "10px";
element.style.background = "-webkit-linear-gradient(white, grey);"
/// declare variables and work out the mid-point
var doc = hypeDocument.documentId();
var docWidth = parseInt(hypeDocument.getElementById(doc).style.width);
var positionX = (document.body.clientWidth - docWidth) / 2 + parseInt(element.style.left);
var positionY = parseInt(element.style.top) - document.body.scrollTop;
var midPointX = positionX + (parseInt(element.style.width) / 2);
var midPointY = positionY + (parseInt(element.style.height) / 2);
/// Actions for when the mouse moves (over each quarter in this case)
element.onmousemove = function (event) {
var tempX = event.clientX;
var tempY = event.clientY;
if (tempX > positionX && tempX < midPointX && tempY < midPointY ) { /// top left corner
/// Actions after mouse moves over the corner
hypeDocument.getElementById('text').style.transform = "scale3d(1.17, 1.17, 1.17)";
element.style.boxShadow = "5px 0px 10px #666";
element.style.webkitTransform = "rotateX(15deg) rotateY(-5deg) rotateZ(0deg) scale3d(1.07, 1.07, 1.07)";
}
if (tempX > positionX && tempX > midPointX && tempY < midPointY ) { /// top right corner
/// Actions after mouse moves over the corner
hypeDocument.getElementById('text').style.transform = "scale3d(1.17, 1.17, 1.17)";
element.style.boxShadow = "-5px 0px 10px #666";
element.style.webkitTransform = "rotateX(15deg) rotateY(5deg) rotateZ(0deg) scale3d(1.07, 1.07, 1.07)";
}
if (tempX > positionX && tempX < midPointX && tempY > midPointY ) { /// bottom left corner
/// Actions after mouse moves over the corner
hypeDocument.getElementById('text').style.transform = "scale3d(1.17, 1.17, 1.17)";
element.style.boxShadow = "2px -5px 10px #666";
element.style.webkitTransform = "rotateX(-15deg) rotateY(-5deg) rotateZ(0deg) scale3d(1.07, 1.07, 1.07)";
}
if (tempX > positionX && tempX > midPointX && tempY > midPointY ) { /// bottom right corner
/// Actions after mouse moves over the corner
hypeDocument.getElementById('text').style.transform = "scale3d(1.17, 1.17, 1.17)";
element.style.boxShadow = "-2px -5px 10px #666";
element.style.webkitTransform = "rotateX(-15deg) rotateY(5deg) rotateZ(0deg) scale3d(1.07, 1.07, 1.07)";
}
}
To reset the element when you “Mouse Out” run this code reset() on Mouse Out:
element.style.transform = "";
element.style.boxShadow = "";
hypeDocument.getElementById('text').style.transform = "";
Basically you’re getting rid of any transitions and placing the element (and any other elements) back to their original states.
Hope this is useful to somebody.
imitationKlocv2.zip (40.7 KB)