Created
August 6, 2018 09:09
-
-
Save Farmatique/860189d07f0695f2f7c5bc12f54aefb8 to your computer and use it in GitHub Desktop.
Media Query watcher
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // source: https://greensock.com/forums/topic/18719-how-to-manage-gsap-animation-in-mobile-device/ | |
| function installMediaQueryWatcher(mediaQuery, layoutChangedCallback) { | |
| var mql = window.matchMedia(mediaQuery); | |
| mql.addListener(function (e) { return layoutChangedCallback(e.matches); }); | |
| layoutChangedCallback(mql.matches); | |
| } | |
| // example below | |
| installMediaQueryWatcher("(min-width: 600px)", function(matches) { | |
| if (matches) { | |
| TweenMax.to(".red", 1, { x: 200 }); | |
| TweenMax.to(".blue", 1, { x: 0 }); | |
| } else { | |
| TweenMax.to(".red", 1, { x: 0 }); | |
| TweenMax.to(".blue", 1, { x: 200 }); | |
| } | |
| }); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment