Skip to content

Instantly share code, notes, and snippets.

@refack
Created July 23, 2014 11:01
Show Gist options
  • Save refack/ed13538a5d8775cf997b to your computer and use it in GitHub Desktop.
Save refack/ed13538a5d8775cf997b to your computer and use it in GitHub Desktop.
$(function() {
var x, y;
var items = [].slice.call(document.querySelectorAll('*')).filter(function(el) {
if (el.getClientRects().length == 0)
return false;
var ret = !(el.dataset['noMove'] === '');
if (!ret)
console.log(el.dataset);
return ret;
}).map(function(el) {
var rect = el.getBoundingClientRect();
el.x = rect.left;
el.y = rect.top;
el.w = rect.right - rect.left;
el.h = rect.bottom - rect.top;
el.fX = 100;
el.fY = 1000;
return el;
});
document.addEventListener('dragover', function(evt) {
x = evt.clientX;
y = evt.clientY;
}, false);
document.addEventListener('mousemove', function(evt) {
x = evt.clientX;
y = evt.clientY;
}, false);
(function _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);
})();
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment