Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

JavaScript

How do you rotate an element in real time as your device (mobile) changes orientation?

I'm looking to have an element pivot and rotate from a central point around the screen, as you tilt your phone side-ways. It has be in real time too. Whats the best approach to achieve this? using a media query or javascript?

Thanks

1 Answer

I would say you'd need to use javascript for this, using something like deviceorientation. Below is a link to the info I found on the MDN but note it is listed as experimental, meaning 'its defining spec is not stable and likely to change significantly. Its syntax and behavior is therefore subject to change in future versions of browsers as the specification changes.'

https://developer.mozilla.org/en-US/docs/Web/API/Detecting_device_orientation