I have some doubts about the "best" current method to distinguish Javascript functions in certain screen sizes, because all answers say something different and they don't convince much. As far as I understand, the methods to build "responsive Javascript functions" are:
matchMedia() function
if (window.matchMedia('(max-width: 500px)').matches) {
width() function applied to window
if ($(window).width() < 500) {
And another method that I haven't seen here is:
if ($(".sampleClass").css("float") == "none") {
that basically check for any CSS propriety that change in a CSS media query:
.sampleClass {float:left;}
@media only screen and (max-width: 800px){
.sampleClass {float:none;}
}
What's the current "best" method in order to write jQuery functions in certain screen sizes?