Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Uncaught TypeError: Cannot read property 'x' of undefined #55

Open
justrealmilk opened this issue Aug 17, 2018 · 20 comments
Open

Uncaught TypeError: Cannot read property 'x' of undefined #55

justrealmilk opened this issue Aug 17, 2018 · 20 comments

Comments

@justrealmilk
Copy link

No description provided.

@brograhamer
Copy link

I have the same issue.

@bumper-yusuf-ozunlu
Copy link

Same here too

@gijsroge
Copy link
Owner

Please provide a demo showing this issue. Either by Codepen, jsfiddle, anything really.. :)

@vrockcm
Copy link

vrockcm commented Dec 31, 2018

https://gyazo.com/16e39433f8684cf0bf75bad42207f70e
It only happens when you are scrolling for some reason.

e2d060a1fde9a330f06d730476332e1d

@gijsroge
Copy link
Owner

@vrockcm thanks but please read my previous reply. Thanks!

@vrockcm
Copy link

vrockcm commented Dec 31, 2018

I tried to do it in jsfiddle but the error didn't pop up. Ill try codepen and see what happens tomorrow. 🙂

@vrockcm
Copy link

vrockcm commented Dec 31, 2018

https://codepen.io/anon/pen/oJoMRJ
Here you go.

@LachieKimber
Copy link

I can't replicate the issue intentionally, but yes the issue happens to me. The error prevents the element that caused the tilt issue to no longer tilt. I even managed to somehow replicate the issue in the above codepen.

@stilltli
Copy link

Any updates on the issue? I get the same error

@Hackinet
Copy link

Hackinet commented Jul 2, 2019

Well, I just disabled the X-axis. Tbh the change in effect isn't even much noticeable.

 $('.someClass').tilt({
 maxTilt:        10,
disableAxis:    'X',   // What axis should be disabled. Can be X or Y.
});

@batata004
Copy link

No update into this? This bug still happens in JUL/2019!

@PowerMostafa
Copy link

I fix it by this way I hope it works
<div data-tilt-axis="x" ></div>

@juli2a
Copy link

juli2a commented Dec 20, 2019

This error appears if you didn't moving a mouse over a tilt element before, and you are scrolling a page and cursor is over the tilt element, and then leaves it, without moving of mouse. In this case the tilt effect doesn't work only on this element

@diabysidim
Copy link

Go to your file src/tilt.jquery.js
Check if this.mousePositions is null just like this.

if(this.mousePositions){

            const percentageX = (this.mousePositions.x - left) / width;
            const percentageY = (this.mousePositions.y - top) / height;
            // x or y position inside instance / width of instance = percentage of position inside instance * the max tilt value
            const tiltX = ((this.settings.maxTilt / 2) - ((percentageX) * this.settings.maxTilt)).toFixed(2);
            const tiltY = (((percentageY) * this.settings.maxTilt) - (this.settings.maxTilt / 2)).toFixed(2);
            // angle
            const angle = Math.atan2(this.mousePositions.x - (left+width/2),- (this.mousePositions.y - (top+height/2)) )*(180/Math.PI);
            // Return x & y tilt values
            return {tiltX, tiltY, 'percentageX': percentageX * 100, 'percentageY': percentageY * 100, angle};
        }

@toddpadwick
Copy link

I get the same issue, when scrolling, if the mouse ends up over an element, it triggers an error blocking the script from re-running on that element even when the mouse starts moving again.

@MaksymJ
Copy link

MaksymJ commented Jun 1, 2020

Go to your file src/tilt.jquery.js
Check if this.mousePositions is null just like this.

if(this.mousePositions){

            const percentageX = (this.mousePositions.x - left) / width;
            const percentageY = (this.mousePositions.y - top) / height;
            // x or y position inside instance / width of instance = percentage of position inside instance * the max tilt value
            const tiltX = ((this.settings.maxTilt / 2) - ((percentageX) * this.settings.maxTilt)).toFixed(2);
            const tiltY = (((percentageY) * this.settings.maxTilt) - (this.settings.maxTilt / 2)).toFixed(2);
            // angle
            const angle = Math.atan2(this.mousePositions.x - (left+width/2),- (this.mousePositions.y - (top+height/2)) )*(180/Math.PI);
            // Return x & y tilt values
            return {tiltX, tiltY, 'percentageX': percentageX * 100, 'percentageY': percentageY * 100, angle};
        }

thank you so much, that solves this small issue!

@ali-vs
Copy link

ali-vs commented Jun 18, 2020

Go to your file src/tilt.jquery.js
Check if this.mousePositions is null just like this.

if(this.mousePositions){

            const percentageX = (this.mousePositions.x - left) / width;
            const percentageY = (this.mousePositions.y - top) / height;
            // x or y position inside instance / width of instance = percentage of position inside instance * the max tilt value
            const tiltX = ((this.settings.maxTilt / 2) - ((percentageX) * this.settings.maxTilt)).toFixed(2);
            const tiltY = (((percentageY) * this.settings.maxTilt) - (this.settings.maxTilt / 2)).toFixed(2);
            // angle
            const angle = Math.atan2(this.mousePositions.x - (left+width/2),- (this.mousePositions.y - (top+height/2)) )*(180/Math.PI);
            // Return x & y tilt values
            return {tiltX, tiltY, 'percentageX': percentageX * 100, 'percentageY': percentageY * 100, angle};
        }

Where should i put this code?

@bmrafiq
Copy link

bmrafiq commented Jul 24, 2020

I have the same issue :(

@bmrafiq
Copy link

bmrafiq commented Jul 24, 2020

@diabysidim thank you. Your solution is worked for me.

@jonathanarbely
Copy link

Put the whole block in a try/catch:

try {
   const percentageX = (this.mousePositions.x - left) / width;
    const percentageY = (this.mousePositions.y - top) / height;
   // x or y position inside instance / width of instance = percentage of position inside instance * the max tilt value
   const tiltX = ((this.settings.maxTilt / 2) - ((percentageX) * this.settings.maxTilt)).toFixed(2);
   const tiltY = (((percentageY) * this.settings.maxTilt) - (this.settings.maxTilt / 2)).toFixed(2);
   // angle
   const angle = Math.atan2(this.mousePositions.x - (left+width/2),- (this.mousePositions.y - (top+height/2)) )*(180/Math.PI);
   // Return x & y tilt values
   return {tiltX, tiltY, 'percentageX': percentageX * 100, 'percentageY': percentageY * 100, angle};
} catch(e){}

jonathanarbely added a commit to jonathanarbely/tilt.js that referenced this issue Feb 7, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests