/**
* GRID DIRECTION
*/
var gridDirection = {
wrap: document.getElementById('grid'), // Main element
throttleBuffer: 10, // Mouse event throttle limit (function runs p/second)
scaleBuffer: 0.1, // Scale buffer for single direction paths
/**
* Initialize events
*/
init: function () {
var _g = this;
_g.bindEvents();
},
/**
* Bind mouse events and throttles
*/
bindEvents: function () {
var _g = gridDirection;
_g.poll = new Date().getTime(); // Set initial poll timestamp
// Mouse move within grid
_g.wrap.addEventListener('mousemove', function (e) {
var now = new Date().getTime();
if (now > _g.poll + _g.throttleBuffer) {
// Within throttle buffer range
_g.poll = now;
_g.offsetCalc(e);
}
});
// Mouse out grid
_g.wrap.addEventListener('mouseout', function (e) {
var remove = false;
// Check if mouse out of grid and not inner elements
if (e.toElement === null) {
remove = true;
} else if (e.toElement.parentElement !== _g.wrap) {
remove = true;
}
if (remove) {
// Remove data attributes
var elems = _g.wrap.getElementsByTagName('div');
for (var i = 0; i < elems.length; i++) {
elems[i].removeAttribute('data-direction');
elems[i].removeAttribute('data-distance');
}
}
});
},
/**
* Calculate offsets, distances and apply attributes
*/
offsetCalc: function (e) {
_g = gridDirection;
// Main grid coords
var wrapOffset = {
x: _g.wrap.offsetLeft,
y: _g.wrap.offsetTop
};
// Main grid size
var wrapSize = {
x: _g.wrap.offsetWidth,
y:...
Please Whitelist JSFiddle in your content blocker.
Help keep JSFiddle free for always by one of two ways:
Whitelist JSFiddle in your content blocker (two clicks)
Go PRO and get access to additional PRO features →
Join the 4+ million users, and keep the JSFiddle dream alive.
Ad-free
All ads in the editor and listing pages are turned completely off.
Use pre-released features
You get to try and use features (like the Palette Color Generator) months before everyone else.
Fiddle collections
Sort and categorize your Fiddles into multiple collections.
Private collections and fiddles
You can make as many Private Fiddles, and Private Collections as you wish!
Console
Debug your Fiddle with a minimal built-in JavaScript console.