Skip to content

Commit

Permalink
ensure FF support by fixing mouse event
Browse files Browse the repository at this point in the history
solves #20
  • Loading branch information
hellsan631 committed Nov 10, 2015
1 parent 884dfbe commit a5116a0
Show file tree
Hide file tree
Showing 5 changed files with 53 additions and 2 deletions.
2 changes: 1 addition & 1 deletion demo/assets/css/perspectiveRules.css
Original file line number Diff line number Diff line change
Expand Up @@ -41,5 +41,5 @@
transform-style: preserve-3d;
-webkit-perspective: 1000;
backface-visibility: hidden;
perspective: 1000;
perspective: 1000px;
}
17 changes: 17 additions & 0 deletions demo/jquery.logosDistort.js
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@
//bind mouse movement to element
if (this.elements[0]) {
this._addEvent(window, 'mousemove', function(e) {
_this.patchEvent(e);
_this.elements.forEach(function(ele){
var fromX = Math.abs(e.x - ele.distort.center.x);
var fromY = Math.abs(e.y - ele.distort.center.y);
Expand All @@ -95,6 +96,7 @@

} else {
this._addEvent(window, 'mousemove', function(e) {
_this.patchEvent(e);
var fromX = Math.abs(e.x - _this.elements.distort.center.x);
var fromY = Math.abs(e.y - _this.elements.distort.center.y);

Expand All @@ -110,13 +112,15 @@
//bind mouse movement to element
if (this.elements[0]) {
this._addEvent(window, 'mousemove', function(e) {
_this.patchEvent(e);
_this.elements.forEach(function(ele){
ele.distort.mouseX = e.x;
ele.distort.mouseY = e.y;
});
});
} else {
this._addEvent(window, 'mousemove', function(e) {
_this.patchEvent(e);
_this.elements.distort.mouseX = e.x;
_this.elements.distort.mouseY = e.y;
});
Expand All @@ -127,6 +131,7 @@
//bind mouse movement to element
if (this.elements[0]) {
this._addEvent(window, 'mousemove', function(e) {
_this.patchEvent(e);
_this.elements.forEach(function(ele){
var fromX = Math.abs(e.x - ele.distort.center.x);
var fromY = Math.abs(e.y - ele.distort.center.y);
Expand All @@ -140,6 +145,7 @@

} else {
this._addEvent(window, 'mousemove', function(e) {
_this.patchEvent(e);
var fromX = Math.abs(e.x - _this.elements.distort.center.x);
var fromY = Math.abs(e.y - _this.elements.distort.center.y);

Expand Down Expand Up @@ -175,6 +181,16 @@
}
};

logosDistort.prototype.patchEvent = function(event) {
if(!event.x) {
event.x = event.clientX || event.layerX;
}

if(!event.y) {
event.y = event.clientY || event.layerY;
}
};

logosDistort.prototype.destroy = function() {
this.clearEvents();
this.elements.forEach(function(ele){
Expand All @@ -186,6 +202,7 @@
if (window.addEventListener) {
element.addEventListener(type, fn, false);
} else if (window.attachEvent) {
console.log('wep');
element.attachEvent(type, fn);
}

Expand Down
17 changes: 17 additions & 0 deletions dist/jquery.logosDistort.js
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@
//bind mouse movement to element
if (this.elements[0]) {
this._addEvent(window, 'mousemove', function(e) {
_this.patchEvent(e);
_this.elements.forEach(function(ele){
var fromX = Math.abs(e.x - ele.distort.center.x);
var fromY = Math.abs(e.y - ele.distort.center.y);
Expand All @@ -95,6 +96,7 @@

} else {
this._addEvent(window, 'mousemove', function(e) {
_this.patchEvent(e);
var fromX = Math.abs(e.x - _this.elements.distort.center.x);
var fromY = Math.abs(e.y - _this.elements.distort.center.y);

Expand All @@ -110,13 +112,15 @@
//bind mouse movement to element
if (this.elements[0]) {
this._addEvent(window, 'mousemove', function(e) {
_this.patchEvent(e);
_this.elements.forEach(function(ele){
ele.distort.mouseX = e.x;
ele.distort.mouseY = e.y;
});
});
} else {
this._addEvent(window, 'mousemove', function(e) {
_this.patchEvent(e);
_this.elements.distort.mouseX = e.x;
_this.elements.distort.mouseY = e.y;
});
Expand All @@ -127,6 +131,7 @@
//bind mouse movement to element
if (this.elements[0]) {
this._addEvent(window, 'mousemove', function(e) {
_this.patchEvent(e);
_this.elements.forEach(function(ele){
var fromX = Math.abs(e.x - ele.distort.center.x);
var fromY = Math.abs(e.y - ele.distort.center.y);
Expand All @@ -140,6 +145,7 @@

} else {
this._addEvent(window, 'mousemove', function(e) {
_this.patchEvent(e);
var fromX = Math.abs(e.x - _this.elements.distort.center.x);
var fromY = Math.abs(e.y - _this.elements.distort.center.y);

Expand Down Expand Up @@ -175,6 +181,16 @@
}
};

logosDistort.prototype.patchEvent = function(event) {
if(!event.x) {
event.x = event.clientX || event.layerX;
}

if(!event.y) {
event.y = event.clientY || event.layerY;
}
};

logosDistort.prototype.destroy = function() {
this.clearEvents();
this.elements.forEach(function(ele){
Expand All @@ -186,6 +202,7 @@
if (window.addEventListener) {
element.addEventListener(type, fn, false);
} else if (window.attachEvent) {
console.log('wep');
element.attachEvent(type, fn);
}

Expand Down
2 changes: 1 addition & 1 deletion dist/jquery.logosDistort.min.js

Large diffs are not rendered by default.

17 changes: 17 additions & 0 deletions src/jquery.logosDistort.js
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@
//bind mouse movement to element
if (this.elements[0]) {
this._addEvent(window, 'mousemove', function(e) {
_this.patchEvent(e);
_this.elements.forEach(function(ele){
var fromX = Math.abs(e.x - ele.distort.center.x);
var fromY = Math.abs(e.y - ele.distort.center.y);
Expand All @@ -95,6 +96,7 @@

} else {
this._addEvent(window, 'mousemove', function(e) {
_this.patchEvent(e);
var fromX = Math.abs(e.x - _this.elements.distort.center.x);
var fromY = Math.abs(e.y - _this.elements.distort.center.y);

Expand All @@ -110,13 +112,15 @@
//bind mouse movement to element
if (this.elements[0]) {
this._addEvent(window, 'mousemove', function(e) {
_this.patchEvent(e);
_this.elements.forEach(function(ele){
ele.distort.mouseX = e.x;
ele.distort.mouseY = e.y;
});
});
} else {
this._addEvent(window, 'mousemove', function(e) {
_this.patchEvent(e);
_this.elements.distort.mouseX = e.x;
_this.elements.distort.mouseY = e.y;
});
Expand All @@ -127,6 +131,7 @@
//bind mouse movement to element
if (this.elements[0]) {
this._addEvent(window, 'mousemove', function(e) {
_this.patchEvent(e);
_this.elements.forEach(function(ele){
var fromX = Math.abs(e.x - ele.distort.center.x);
var fromY = Math.abs(e.y - ele.distort.center.y);
Expand All @@ -140,6 +145,7 @@

} else {
this._addEvent(window, 'mousemove', function(e) {
_this.patchEvent(e);
var fromX = Math.abs(e.x - _this.elements.distort.center.x);
var fromY = Math.abs(e.y - _this.elements.distort.center.y);

Expand Down Expand Up @@ -175,6 +181,16 @@
}
};

logosDistort.prototype.patchEvent = function(event) {
if(!event.x) {
event.x = event.clientX || event.layerX;
}

if(!event.y) {
event.y = event.clientY || event.layerY;
}
};

logosDistort.prototype.destroy = function() {
this.clearEvents();
this.elements.forEach(function(ele){
Expand All @@ -186,6 +202,7 @@
if (window.addEventListener) {
element.addEventListener(type, fn, false);
} else if (window.attachEvent) {
console.log('wep');
element.attachEvent(type, fn);
}

Expand Down

0 comments on commit a5116a0

Please sign in to comment.