Skip to content

Instantly share code, notes, and snippets.

@salmenbej
Last active August 29, 2015 14:08
Show Gist options
  • Save salmenbej/4d2f168c88688f51be4f to your computer and use it in GitHub Desktop.
Save salmenbej/4d2f168c88688f51be4f to your computer and use it in GitHub Desktop.
Check the Portrait / Landscape mode on mobile device with ssm.js ( http://www.simplestatemanager.com/ )
ssm.addConfigOption({name:"orientation", test: function(){
//landscape mode
if(this.state.orientation === "landscape" && window.innerWidth >= window.innerHeight){
console.log('landscape');
return true;
}
//portrait mode
else if (this.state.orientation === "portrait" && window.innerWidth <= window.innerHeight){
console.log('portrait');
return true;
}
else {
return false;
}
}});
//How to use it
ssm.addStates([
{
id: 'tablet',
minWidth: 768,
maxWidth: 1023,
orientation: 'portrait',
onEnter: function(){
console.log('enter tablet portrait mode');
}
},{
id: 'tablet',
minWidth: 768,
maxWidth: 1023,
orientation: 'landscape',
onEnter: function(){
console.log('enter tablet landscape mode');
}
}
]);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment