Skip to content

Instantly share code, notes, and snippets.

@Farmatique
Created August 6, 2018 09:09
Show Gist options
  • Save Farmatique/860189d07f0695f2f7c5bc12f54aefb8 to your computer and use it in GitHub Desktop.
Save Farmatique/860189d07f0695f2f7c5bc12f54aefb8 to your computer and use it in GitHub Desktop.
Media Query watcher
// 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