Menu icon Foundation
Joshua Scott about 3 years ago

How are you trying to use it? Can you provide us with your code?

Dimitris Gerasopoulos about 3 years ago

In order to use this javascript utility you must first initialize foundation

$(document).foundation();

 

Joshua Scott about 3 years ago

Here is an example that shows using the Foundation.MediaQuery.current and also updating the value as the media query changes. Please see the comments in the code.

<!doctype html>
<html class="no-js" lang="en" dir="ltr">
  <head>
    <meta charset="utf-8">
    <meta http-equiv="x-ua-compatible" content="ie=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Media Query Test</title>
    <link rel="stylesheet" href="https://cdn.jsdelivr.net/foundation/6.2.4/foundation.min.css">
  </head>
  <body>
    <div id="status">Current Media Query <span class="mq"></span></div>
    <script src="https://code.jquery.com/jquery-1.12.4.min.js"></script>
    <script src="https://cdn.jsdelivr.net/foundation/6.2.4/foundation.min.js"></script>

    <script>
      $(document).foundation();
      $('.mq').text(Foundation.MediaQuery.current);
      <!-- Uses jQuery to set the initial value of the media query and write to the span -->

      $(window).on('changed.zf.mediaquery', function(event, newSize, oldSize) {
        <!-- detects changes from one media query to the next -->

        $('.mq').text(newSize);
        <!-- rewrites the value in span .mq to the current media query value -->
      });
    </script>
  </body>
</html>