Size modes Size Mode for Syncfusion EJ2 JavaScript Controls

10 May 20239 minutes to read

An application that is designed to be accessed through a web browser on various devices, including desktop computers and mobile devices, may have a distinct layout or user interface on a mobile device compared to a desktop computer to better suit the smaller screen size.

Syncfusion JavaScript controls support both touch (bigger) and normal size modes. Touch mode creates a responsive design for mobile devices by adding the e-bigger class, which enhances interactions, visibility, and the overall experience.

Size mode for application

The user can enable touch mode (bigger) for the entire application by adding the e-bigger class to the body element in the index.html file as follows:

  <body className="e-bigger">
    ...
  </body>

Size mode for a control

The user can enable touch mode (bigger) for a control by adding the e-bigger class to the div element that contains the control. Another way of enabling touch mode is by adding the e-bigger class using the available cssClass property of the control.

// initialize button control
var button = new ej.buttons.Button({ content: 'Button' });
button.appendTo('#element')
<!DOCTYPE html><html lang="en"><head>
    <title>EJ2 Animation</title>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta name="description" content="Typescript UI Controls">
    <meta name="author" content="Syncfusion">
    <link href="index.css" rel="stylesheet">
    <link href="https://cdn.syncfusion.com/ej2/24.2.3/ej2-base/styles/material.css" rel="stylesheet">
    <link href="https://cdn.syncfusion.com/ej2/24.2.3/ej2-buttons/styles/material.css" rel="stylesheet">
    
    
<script src="https://cdn.syncfusion.com/ej2/24.2.3/dist/ej2.min.js" type="text/javascript"></script>
<script src="https://cdn.syncfusion.com/ej2/syncfusion-helper.js" type ="text/javascript"></script>
</head>

<body>
    <div id="container" class="e-bigger">
        
        <button id="element">Button</button>
    </div>


<script>
var ele = document.getElementById('container');
if(ele) {
  ele.style.visibility = "visible";
}   
      </script>
<script src="index.js" type="text/javascript"></script>
</body></html>

Change size mode for application at runtime

The user can change the size mode of the application between touch and normal (mouse) mode at runtime by adding and removing the e-bigger class. The following steps explain how to change the size mode of an application at runtime:

var touchButton = new ej.buttons.Button({ content: 'Touch Mode' });
touchButton.appendTo('#touch')
touchButton.element.onclick = () => {
    document.body.classList.add('e-bigger');
    }
    // initialize mouse button control
var mouseButton = new ej.buttons.Button({ content: 'Mouse Mode' });
mouseButton.appendTo('#mouse')
mouseButton.element.onclick = () => {
    document.body.classList.remove('e-bigger');
    }
    // initialize Calendar component
var calendar = new ej.calendars.Calendar();
calendar.appendTo('#calendar')
<!DOCTYPE html><html lang="en"><head>
    <title>EJ2 Animation</title>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta name="description" content="Typescript UI Controls">
    <meta name="author" content="Syncfusion">
    <link href="index.css" rel="stylesheet">
    <link href="https://cdn.syncfusion.com/ej2/24.2.3/ej2-base/styles/material.css" rel="stylesheet">
    <link href="https://cdn.syncfusion.com/ej2/24.2.3/ej2-buttons/styles/material.css" rel="stylesheet">
    <link href="https://cdn.syncfusion.com/ej2/24.2.3/ej2-calendars/styles/material.css" rel="stylesheet">
    
    
<script src="https://cdn.syncfusion.com/ej2/24.2.3/dist/ej2.min.js" type="text/javascript"></script>
<script src="https://cdn.syncfusion.com/ej2/syncfusion-helper.js" type ="text/javascript"></script>
</head>

<body>
    
    <div id="container">
        <div>
            <button id="touch"></button>
            <button id="mouse"></button>
        </div>
        <div class="control">
            <div id="calendar"></div>
        </div>
    </div>


<script>
var ele = document.getElementById('container');
if(ele) {
  ele.style.visibility = "visible";
}   
      </script>
<script src="index.js" type="text/javascript"></script>
</body></html>

Change size mode for a control at runtime

The user can change the size mode of a control between touch and normal (mouse) mode at runtime by setting the e-bigger CSS class.

var touchButton = new ej.buttons.Button({ content: 'Touch Mode' });
touchButton.appendTo('#touch')
touchButton.element.onclick = () => {
        var controls = document.querySelectorAll('.control');
        for (var index = 0; index < controls.length; index++) {
            controls[index].classList.add('e-bigger');
        }
    }
    // initialize mouse button control
var mouseButton = new ej.buttons.Button({ content: 'Mouse Mode' });
mouseButton.appendTo('#mouse')
mouseButton.element.onclick = () => {
        var controls = document.querySelectorAll('.control');
        for (var index = 0; index < controls.length; index++) {
            controls[index].classList.remove('e-bigger');
        }
    }
    // initialize Calendar component
var calendar = new ej.calendars.Calendar();
calendar.appendTo('#calendar')
<!DOCTYPE html><html lang="en"><head>
    <title>EJ2 Animation</title>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta name="description" content="Typescript UI Controls">
    <meta name="author" content="Syncfusion">
    <link href="index.css" rel="stylesheet">
    <link href="https://cdn.syncfusion.com/ej2/24.2.3/ej2-base/styles/material.css" rel="stylesheet">
    <link href="https://cdn.syncfusion.com/ej2/24.2.3/ej2-buttons/styles/material.css" rel="stylesheet">
    <link href="https://cdn.syncfusion.com/ej2/24.2.3/ej2-calendars/styles/material.css" rel="stylesheet">
    
    
<script src="https://cdn.syncfusion.com/ej2/24.2.3/dist/ej2.min.js" type="text/javascript"></script>
<script src="https://cdn.syncfusion.com/ej2/syncfusion-helper.js" type ="text/javascript"></script>
</head>

<body>
    
    <div id="container">
        <div>
            <button id="touch"></button>
            <button id="mouse"></button>
        </div>
        <div class="control">
            <div id="calendar"></div>
        </div>
    </div>


<script>
var ele = document.getElementById('container');
if(ele) {
  ele.style.visibility = "visible";
}   
      </script>
<script src="index.js" type="text/javascript"></script>
</body></html>

See also