Shapes in EJ2 JavaScript Skeleton control

29 Aug 20235 minutes to read

The Skeleton control support various built-in shape variants to design layout of the page. You can use the shape property to create a preview of any layout.

The Skeleton component supports the following shapes,

Circle skeleton shape

// Initialize Skeleton control for circle shape
var circle = new ej.notifications.Skeleton({
    shape: 'Circle',
    width: "48px"
});

// Render initialized Skeleton.
circle.appendTo('#circleSkeleton');

Square skeleton shape

// Initialize Skeleton control for square shape
var square = new ej.notifications.Skeleton({
    shape: 'Square',
    width: "48px"
});

// Render initialized Skeleton.
square.appendTo('#squareSkeleton');

Rectangle skeleton shape

// Initialize Skeleton control for rectangle shape
var rect = new ej.notifications.Skeleton({
    shape: "Rectangle",
    height: '50px'
});

// Render initialized Skeleton.
rect.appendTo('#rectSkeleton');

Text skeleton shape

// Initialize Skeleton control for text shape
var text = new ej.notifications.Skeleton({
    shape: "Text",
    height: "15px"
})

// Render initialized Skeleton.
text.appendTo('#textSkeleton');

Below example demonstrates the above functionalities of a Skeleton control.

ej.base.enableRipple(true);

// Initialize Skeleton control for circle shape
var cardProfile = new ej.notifications.Skeleton({shape: 'Circle', width: '60px', height: '60px'});

// Render initialized Skeleton.
cardProfile.appendTo('#cardProfile');

var text1 = new ej.notifications.Skeleton({width: '30%', height: '15px'});
text1.appendTo('#text1');

var text2 = new ej.notifications.Skeleton({width: '15%', height: '15px'});
text2.appendTo('#text2');

var cardImage = new ej.notifications.Skeleton({shape: 'Rectangle', width: '100%', height: '150px'});
cardImage.appendTo('#cardImage');

var rightOption = new ej.notifications.Skeleton({shape: 'Rectangle', width: '20%', height: '32px'});
rightOption.appendTo('#rightOption');

var leftOption = new ej.notifications.Skeleton({shape: 'Rectangle', width: '20%', height: '32px'});
leftOption.appendTo('#leftOption');
<!DOCTYPE html><html lang="en"><head>
    <title>EJ2 Skeleton</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="https://cdn.syncfusion.com/ej2/25.1.35/ej2-base/styles/material.css" rel="stylesheet">
    <link href="https://cdn.syncfusion.com/ej2/25.1.35/ej2-notifications/styles/material.css" rel="stylesheet">
    <link href="styles.css" rel="stylesheet">
    
    
<script src="https://cdn.syncfusion.com/ej2/25.1.35/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 id="skeletonCard" class="e-card" style="display: block">
            <div class="cardProfile">
                <div id="cardProfile"></div>
            </div>
            <div class="cardinfo">
                <div id="text1"></div><br>
                <div id="text2"></div>
            </div>
            <div class="cardContent">
                <div id="cardImage"></div>
            </div>
            <div class="cardoptions">
                <div id="rightOption"></div>
                <div id="leftOption"></div>
            </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>