Open In App

Foundation CSS JavaScript

Last Updated : 22 Aug, 2022
Improve
Improve
Like Article
Like
Save
Share
Report

A Foundation CSS is an open-source and responsive front-end framework created by ZURB in September 2011 that makes it simple to create stunning responsive websites, apps, and emails that operate on any device. Many companies, like Facebook, eBay, Mozilla, Adobe, and even Disney, use it. The framework is based on bootstrap, which is similar to SaaS. It’s more complex, versatile, and configurable. It also comes with a command-line interface, making it simple to use with module bundlers. Email framework provides you with responsive HTML emails, which can be read on any device. Foundation for Apps allows you to build fully responsive web applications.

Foundation CSS JavaScript:

  • Installing & Initialization:  We can add Foundation CSS JavaScript by using NPM install and CDN link.
  • Using Plugins: The Plugins are attached to HTML elements using data attributes. The data attribute will match the name of the plugin.
  • Configuring Plugins: All the plugins have configuration settings that customize their work. 
  • Adding Plugins After Page Load: Any plugins won’t be initialized by default if we want to add new HTML to DOM. Call the foundation() function to check for new plugins.
  • Adding Content to Plugins:  We have added a global reInit() method that will remove and reapply event listeners, and update the plugin’s instance data for relevant information.
  • Programmatic Use: Some plugins can be created programmatically in JavaScript as the plugin is a class on the Foundation object, with a constructor that accepts two parameters: an element and an object options.
  • Events: Every plugin fires DOM events after functions finish.

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();

Some of the codes are given for reference, the developer can make use of other features as per the need.

Example 1: This example shows the significance of Foundation JS by implementing its initialization.

HTML




<!DOCTYPE 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">
  
    <link rel="stylesheet" href=
  
    <!-- Compressed JavaScript -->
    <script src=
    </script>
    <script src=
    </script>
    <style>
        body {
            margin-left: 10px;
            margin-right: 10px;
        }
    </style>
</head>
  
<body>
    <h1 style="color:green">GeeksforGeeks</h1>
    <h3>Foundation CSS JavaScript</h3>
    <div id="divID">
        <ul class="dropdown menu" data-dropdown-menu>
            <li> <a href="#">Tutorials</a>
                <ul class="menu">
  
                    <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>
                </ul>
            </li>
            <li><a href="#">Student</a>
                <ul class="menu">
                    <li>
                        <a href="#">Campus Ambassador Program</a>
                    </li>
                    <li>
                        <a href="#">Geek Of the Month</a>
                    </li>
                    <li>
                        <a href="#">Placement Course</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>
    </div>
    <script>
        $(document).foundation();
    </script>
</body>
  
</html>


Output:

 

Example 2: The following code demonstrates the Foundation CSS JavaScript using Plugins. We are using accordion by using data attributes namely “data-accordion”, “data-accordion-item” and “data-tab-content”.

HTML




<!DOCTYPE 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">
  
    <link rel="stylesheet" href=
  
    <!-- Compressed JavaScript -->
    <script src=
    </script>
    <script src=
    </script>
    <style>
        body {
            margin-left: 10px;
            margin-right: 10px;
        }
    </style>
</head>
  
<body>
    <h1 style="color:green">GeeksforGeeks</h1>
    <h3>Foundation CSS JavaScript using Plugins</h3>
    <div id="divID">
        <ul class="accordion" data-accordion>
            <li class="accordion-item" data-accordion-item>
                <a href="#" class="accordion-title">Accordion 1</a>
                <div class="accordion-content" data-tab-content>
                    <p>This is the Content of Accordion 1</p>
                </div>
            </li>
  
            <li class="accordion-item" data-accordion-item>
                <a href="#" class="accordion-title">Accordion 2</a>
                <div class="accordion-content" data-tab-content>
                    <p>This is the Content of Accordion 2</p>
                </div>
            </li>
  
            <li class="accordion-item" data-accordion-item>
                <a href="#" class="accordion-title">Accordion 3</a>
                <div class="accordion-content" data-tab-content>
                    <p>This is the Content of Accordion 3</p>
                </div>
            </li>
        </ul>
    </div>
    <script>
        $(document).foundation();
    </script>
</body>
  
</html>


Output:

 

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



Like Article
Suggest improvement
Share your thoughts in the comments

Similar Reads