Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save yankeyhotel/853b7c23550aaec93718 to your computer and use it in GitHub Desktop.
Save yankeyhotel/853b7c23550aaec93718 to your computer and use it in GitHub Desktop.
Use CSS media queries and Javascript together to determine browser width.
/* position static in mobile media queries by default */
#js-media-test { position: static; }
/* and position it relative in larger sizes
you can set the break to whatever makes the most sense */
@media (max-width: 769px) {
#js-media-test { position: relative; }
}
<!-- add this html to just before the closing body tag -->
<div id="js-media-test" class="hide"></div>
// Now you can test the css property much easier than testing
// screen width etc.
$(document).ready(function(){
if ( $('#js-media-test').css("position") == "relative") {
// do something
} else {
// do something else
}
}
@yankeyhotel
Copy link
Author

For a much cooler way of doing the same thing check this out from my friend Boots. https://gist.github.com/bootsified/47b79fbf12ff7eccef66

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment