Open In App

Foundation CSS JavaScript Installation & Initialization

Improve
Improve
Like Article
Like
Save
Share
Report

Foundation CSS is an open-source & responsive front-end framework built by ZURB foundation in September 2011, that makes it easy to design beautiful responsive websites, apps, and emails that look amazing & can be accessible to any device. It is used by many companies such as Facebook, eBay, Mozilla, Adobe, and even Disney. The framework is built on Saas-like bootstrap. It is more sophisticated, flexible, and easily customizable. It also comes with CLI, so it’s easy to use it with module bundlers. It offers the Fastclick.js tool for faster rendering on mobile devices.  

JavaScript Installation:

 We can add Foundation CSS JavaScript to our webpage in 2 ways:

  • Using NPM Install
  • Using CDN Link

We will understand both the ways of using Javascript in Foundation CSS, along with their implementations.

Using NPM Install:

Foundation is available on npm. This package includes all of the source Sass and JavaScript files, as well as compiled CSS and JavaScript, in uncompressed and compressed flavors.

npm install foundation-sites

Using CDN Link:

We can get the required foundation JS from CDN by just inserting the below lines of code in our HTML template:

<script src=”https://cdnjs.cloudflare.com/ajax/libs/foundation/6.0.1/js/vendor/jquery.min.js”></script>
<script src=”https://cdn.jsdelivr.net/npm/foundation-sites@6.5.1/dist/js/foundation.min.js” crossorigin=”anonymous”>
</script>

JavaScript Initialization:

The .foundation() function on the jQuery object, can be utilized to avail every Foundation plugin at once.

Syntax:

$(document).foundation();

Example: This example shows the significance of Foundation JS by implementing it & without implementing it.

Using JS Installation and Initialization:

HTML




<html lang="en">
  
<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>
        Foundation CSS JavaScript Configuration
    </title>
      
    <!-- Compressed CSS -->
    <link rel="stylesheet"
          href=
          crossorigin="anonymous">
            
    <!-- Compressed JavaScript (Foundation JS from CDN) -->
    <script src=
    </script>
    <script src=
            crossorigin="anonymous">
    </script>
</head>
  
<body>
    <h1 style="color:green;">GeeksforGeeks </h1>
    <h3>Foundation CSS dropdown menu example 
        when JS is installed and Initialized
    </h3>
    <ul class="dropdown menu" data-dropdown-menu>
        <li> <a href="#">Tutorials</a>
            <ul class="menu">
                <li>
                    <a href="#">Practice DS & Algo.</a>
                </li>
                <li>
                    <a href="#">Algorithms</a>
                </li>
                <li>
                    <a href="#">Data Structures</a>
                </li>
                <li>
                    <a href="#">Interview Corner</a>
                </li>
                <li>
                    <a href="#">Languages</a>
                </li>
                <li>
                    <a href="#">CS Subjects</a>
                </li>
                <li>
                    <a href="#">GATE</a>
                </li>
                <li>
                    <a href="#">Web Technologies</a>
                </li>
            </ul>
        </li>
        <li><a href="#">Student</a>
            <ul class="menu">
                <li>
                    <a href="#">Campus Ambassador Program</a>
                </li>
                <li>
                    <a href="#">School Ambassador Program</a>
                </li>
                <li>
                    <a href="#">Project</a>
                </li>
                <li>
                    <a href="#">Geek Of the Month</a>
                </li>
                <li>
                    <a href="#">Placement Course</a>
                </li>
                <li>
                    <a href="#">Competitive Programming</a>
                </li>
                <li>
                    <a href="#">Testimonials</a>
                </li>
                <li>
                    <a href="#">Careers</a>
                </li>
            </ul>
        </li>
        <li><a href="#">Jobs</a>
            <ul class="menu">
                <li>
                    <a href="#">Apply for Jobs</a>
                </li>
                <li>
                    <a href="#">Post a Job</a>
                </li>
            </ul>
        </li>
        <li>
            <a href="#">Courses</a>
        </li>
    </ul>
      
    <!-- Js Initialization -->
    <script>
        $(document).foundation();
    </script>
</body>
  
</html>


Output:

With JavaScript installation in Foundation CSS

  • Without Foundation JS Installation and Initialization:

HTML




<html lang="en">
  
<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>
        Foundation CSS JavaScript Configuration
    </title>
      
    <!-- Compressed CSS -->
    <link rel="stylesheet"
          href=
          crossorigin="anonymous">
</head>
  
<body>
    <h1 style="color:green;">GeeksforGeeks </h1>
    <h3>
        Foundation CSS dropdown menu example
        without Foundation JS
    </h3>
    <ul class="dropdown menu" data-dropdown-menu>
        <li> <a href="#">Tutorials</a>
            <ul class="menu">
                <li>
                    <a href="#">Practice DS & Algo.</a>
                </li>
                <li>
                    <a href="#">Algorithms</a>
                </li>
                <li>
                    <a href="#">Data Structures</a>
                </li>
                <li>
                    <a href="#">Interview Corner</a>
                </li>
                <li>
                    <a href="#">Languages</a>
                </li>
                <li>
                    <a href="#">CS Subjects</a>
                </li>
                <li>
                    <a href="#">GATE</a>
                </li>
                <li>
                    <a href="#">Web Technologies</a>
                </li>
            </ul>
        </li>
        <li><a href="#">Student</a>
            <ul class="menu">
                <li>
                    <a href="#">Campus Ambassador Program</a>
                </li>
                <li>
                    <a href="#">School Ambassador Program</a>
                </li>
                <li>
                    <a href="#">Project</a>
                </li>
                <li>
                    <a href="#">Geek Of the Month</a>
                </li>
                <li>
                    <a href="#">Placement Course</a>
                </li>
                <li>
                    <a href="#">Competitive Programming</a>
                </li>
                <li>
                    <a href="#">Testimonials</a>
                </li>
                <li>
                    <a href="#">Careers</a>
                </li>
            </ul>
        </li>
        <li><a href="#">Jobs</a>
            <ul class="menu">
                <li>
                    <a href="#">Apply for Jobs</a>
                </li>
                <li>
                    <a href="#">Post a Job</a>
                </li>
            </ul>
        </li>
        <li>
            <a href="#">Courses</a>
        </li>
    </ul>
</body>
</html>


Output: From the output, we haven’t used the Foundation CSS JavaScript, so the code does not work intended.

Without Foundation JS Installation 

Reference: https://get.foundation/sites/docs/javascript.html#installing



Last Updated : 07 Mar, 2022
Like Article
Save Article
Previous
Next
Share your thoughts in the comments
Similar Reads