Open In App

Foundation CSS JavaScript Miscellaneous Utilities

Last Updated : 02 Feb, 2023
Improve
Improve
Like Article
Like
Save
Share
Report

Foundation CSS is a responsive front-end framework for building web applications. It includes a set of CSS styles and JavaScript functions that can be used to create a  responsive layout and add interactivity to a website.

Foundation CSS JavaScript miscellaneous utilities:

  • Foundation.GetYoDigits([number, namespace]): This function with optional parameters returns a base-36, 6 character long random string with a hyphenated namespace. 
  • Foundation.getFnName(fn):  This function returns a string representation of a named function.
  • Foundation.transitionend():   This function returns the string of the vendor-prefixed version of transitionend events.

Example 1: This code demonstrates how to use the Foundation.GetYoDigits() function.

  • The Foundation.GetYoDigits() function takes two arguments: the length of the ID you want to generate, and a prefix to use for the ID. In this example, the function generates a 6-character ID with the prefix “my-element”
  • We create a button and a div element to display the generated ID and then add an event listener to the button that calls the Foundation.GetYoDigits() function and updates the text content of the div element with the generated ID when the button is clicked.

HTML




<!DOCTYPE html>
<html>
<head>
    <title>Foundation GetYoDigits Example</title>
    <link rel="stylesheet" href=
    <script src=
    </script>
    <script src=
    </script>
</head>
<body>
    <center>
        <h1 style=color:green>GeeksforGeeks</h1>
        <h3> Foundation CSS JavaScript Miscellaneous Utilities</h3>
        <button id="generate-id-button">
            Generate ID
        </button>
        <div id="generated-id"></div>
        <script>
            // Get a reference to the button and generated ID element
            var button = document.getElementById('generate-id-button');
            var generatedID = document.getElementById('generated-id');
  
            button.addEventListener('click', function() {
                // Generate a new ID with the Foundation.GetYoDigits
                var newID = Foundation.GetYoDigits(6, 'my-element-');
                generatedID.textContent = newID;
            });
        </script>
   </center>
</body>
</html>


Output:

 

Example 2: This code demonstrates how to use the Foundation.getFnName() function.

  • In this example, we define a test function and create a button and a div element to display the function name.
  • We then add an event listener to the button that calls the Foundation.getFnName() function and passes in the test function as an argument. 
  • The function returns the name of the function, which is then displayed in the div element when the button is clicked.

HTML




<!DOCTYPE html>
<html>
<head>
  <title>Foundation getFnName Example</title>
  <link rel="stylesheet" href=
    <script src=
    </script>
    <script src=
    </script>
</head>
<body>
    <center>
        <h1 style=color:green>GeeksforGeeks</h1>
        <h3> Foundation CSS JavaScript Miscellaneous Utilities</h3>
        <button id="get-fn-name-button">Get Function Name</button>
        <div id="function-name"></div>
        <script>
            function testFunction() {
                console.log('This is a test function');
            }
            var button = document.getElementById('get-fn-name-button');
            var functionName = document.getElementById('function-name');
              
            button.addEventListener('click', function() {
                // Get the function name with the Foundation.getFnName
                var fnName = Foundation.getFnName(testFunction);
  
                functionName.textContent = fnName;
            });
        </script>
   </center>
</body>
</html>


Output:

 

Example 3:

  • In this example, we create a button and a div element and add a transition to the div element. When the button is clicked, the width of the div element is toggled between 100px and 200px, causing the transition to occur. 
  • We use the Foundation.transitionend() function to listen for the end of the transition, and log a message to the console when the transition is complete.

HTML




<!DOCTYPE html>
<html>
<head>
    <title>Foundation transitionend Example</title>
    <link rel="stylesheet" href=
    <script src=
    </script>
    <script src=
    </script>
</head>
<body>
    <center>
        <h1 style=color:green>GeeksforGeeks</h1>
        <h3> Foundation CSS JavaScript Miscellaneous Utilities</h3>
        <!-- Create a button to trigger the transition -->
        <button id="transition-button">
            Trigger Transition
        </button>
  
        <!-- Create a div to apply the transition to -->
        <div id="transition-div" 
             style="background-color: red; 
                  width: 100px; height: 100px; 
                  transition: width 0.5s ease;">
        </div>
  
        <script>
            var button = document.getElementById('transition-button');
            var transitionDiv = document.getElementById('transition-div');
            button.addEventListener('click', function() {
                // Toggle the width of the 
                // transition div between 100px and 200px
                if (transitionDiv.style.width === '100px') {
                    transitionDiv.style.width = '200px';
                } else {
                    transitionDiv.style.width = '100px';
                }
            });
  
            // Use the Foundation.transitionend function 
            // to listen for the end of the transition
            Foundation.transitionend(transitionDiv, function() {
              console.log('Transition ended');
            });
        </script>
    </center>
</body>
</html>


Output:

 

Reference: https://get.foundation/sites/docs/javascript-utilities.html#miscellaneous



Like Article
Suggest improvement
Previous
Next
Share your thoughts in the comments

Similar Reads