I am doing a little mosaic (if I can call it that). I change the scale and opacity based on the position of the mouse and the center of the image / div.
I calculate distance through vectors using
function calculateDistance(elem, mouseX, mouseY) { return Math.floor(Math.sqrt(Math.pow(mouseX - (elem.offsetLeft + (elem.offsetWidth / 2)), 2) + Math.pow(mouseY - (elem.offsetTop + (elem.offsetHeight / 2)), 2))); }
and im loop through div / images, and if the distance is less than 100, it calculates its opacity / scale.
But I ran into a problem when the animation changing transparency / scaling is a little shaky. It seems that he doubts that he should do something.
Demo = http://jsfiddle.net/Trolstover/x9fpv8pb/5/
Is there a way or shortcut on how to fix this, as I called it shakking or hesitating?
javascript css
Darlyn
source share