diff --git a/index.html b/index.html index fea1011..8f801e2 100644 --- a/index.html +++ b/index.html @@ -185,7 +185,7 @@
@@ -378,6 +378,7 @@ sort.destroy(); y = evt.clientY; }, false); + document.addEventListener('mousemove', function (evt){ x = evt.clientX; y = evt.clientY; @@ -385,22 +386,24 @@ sort.destroy(); (function _loop(){ - var winWidth = window.innerWidth; - var winHeight = window.innerHeight; - var halfWidth = winWidth / 2; - var halfHeight = winHeight / 2; - - var rx = x - winWidth/2; - var ry = winHeight/2 - y; - - items.forEach(function (el){ - var dx = el.w/el.fX * (rx / -halfWidth); - var dy = el.h/el.fY * (ry / halfHeight); - el.style['transform'] = - el.style['-webkit-transform'] = 'translate('+dx+'px,'+dy+'px)'; - }); - - requestAnimationFrame(_loop); + if( x && y ){ + var winWidth = window.innerWidth; + var winHeight = window.innerHeight; + var halfWidth = winWidth / 2; + var halfHeight = winHeight / 2; + + var rx = x - winWidth/2; + var ry = winHeight/2 - y; + + items.forEach(function (el){ + var dx = el.w/el.fX * (rx / -halfWidth); + var dy = el.h/el.fY * (ry / halfHeight); + el.style['transform'] = + el.style['-webkit-transform'] = 'translate('+dx+'px,'+dy+'px)'; + }); + + requestAnimationFrame(_loop); + } })(); })();