Package arez.dom
Class MediaQuery
java.lang.Object
arez.dom.MediaQuery
An observable model that indicates whether a window matches a CSS media query.
A very simple example
import arez.Arez;
import arez.mediaquery.MediaQuery;
import com.google.gwt.core.client.EntryPoint;
import akasha.Console;
public class MediaQueryExample
implements EntryPoint
{
public void onModuleLoad()
{
final MediaQuery mediaQuery = MediaQuery.create( "(max-width: 600px)" );
Arez.context().observer( () ->
DomGlobal.document.querySelector( "#status" ).textContent =
"Screen size Status: " + ( mediaQuery.matches() ? "Narrow" : "Wide" ) );
}
}
-
Method Summary
Modifier and TypeMethodDescriptionstatic MediaQuery
Create an instance of MediaQuery.static MediaQuery
Create an instance of MediaQuery.getQuery()
Return the media query to test against window.akasha.Window
Return the window against which the MediaQuery will run.boolean
matches()
Return true if the media query matches, false otherwise.void
Change the media query to test against.
-
Method Details
-
create
Create an instance of MediaQuery.- Parameters:
query
- the CSS media query to match.- Returns:
- the MediaQuery instance.
-
create
Create an instance of MediaQuery.- Parameters:
window
- the window to test.query
- the CSS media query to match.- Returns:
- the MediaQuery instance.
-
getWindow
Return the window against which the MediaQuery will run.- Returns:
- the window to test.
-
getQuery
Return the media query to test against window.- Returns:
- the associated media query.
-
setQuery
Change the media query to test against. If the component is active then invoking this will ensure that the listener is updated to listen to new query.- Parameters:
query
- the CSS media query.
-
matches
Return true if the media query matches, false otherwise.- Returns:
- true if the media query matches, false otherwise.
-